Advertisement
Guest User

Untitled

a guest
Aug 19th, 2015
188
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2. # code found and bit modified
  3. # http://forum.xda-developers.com/showthread.php?t=2127850
  4. # two options rndis,adb or mtp,adb
  5.  
  6. prevconfig=$(getprop sys.usb.config)
  7.  
  8.  
  9. #if [ "${prevconfig}" != "${prevconfig#rndis}" ] ; then
  10. if [ "${prevconfig}" == "rndis,adb" ] ; then
  11.  
  12. echo 'Is tethering already active?' >&2
  13. exit 1
  14. fi
  15.  
  16. default_interface=$(ip route | head -n 1 | grep rmnet_usb0)
  17. if [ -z "$default_interface" ] ; then
  18.  
  19. echo 'Please turn off your Wi-Fi first.' >&2
  20. exit 1
  21. fi
  22.  
  23.  
  24.  
  25. #creates dev usb0
  26. android-gadget-service enable rndis
  27. sleep 6
  28.  
  29. echo "${prevconfig}" > /cache/usb_tether_prevconfig
  30. setprop sys.usb.config 'rndis,adb'
  31. until [ "$(getprop sys.usb.state)" = 'rndis,adb' ] ; do sleep 1 ; done
  32.  
  33. #change from ipv6 to ipv4
  34. #ip rule add from all lookup main
  35. ip addr flush dev usb0
  36. ip addr add 192.168.22.1/255.255.255.0 dev usb0
  37. ip link set usb0 up
  38.  
  39.  
  40. #enable forwarding
  41.  
  42. echo 1 > /proc/sys/net/ipv4/ip_forward
  43. #syscrl net.ipv4.ip_forward=1
  44. #echo 1 > /proc/sys/net/ipv6/conf/forwarding
  45. #echo 1 > /proc/sys/net/ipv6/conf/forwarding
  46.  
  47. #set iptables
  48. #ip6
  49. #ip6tables -t nat -I POSTROUTING 1 -o rmnet_usb0 -j MASQUERADE
  50. #ip6tables -A FORWARD -i usb0 -j ACCEPT
  51.  
  52. #ip4
  53. #this works but slow
  54. iptables -t nat -I POSTROUTING 1 -o rmnet_usb0 -j MASQUERADE
  55. iptables -A FORWARD -i usb0 -j ACCEPT
  56.  
  57. #iptables -t nat -I POSTROUTING 1 -o rmnet_usb0 -j MASQUERADE
  58. #iptables -I FORWARD 1 --in-interface usb0 -j ACCEPT
  59. #iptables -I INPUT 1 --in-interface usb0 -j ACCEPT
  60. #iptables -A FORWARD -i rmnet_usb0 -j ACCEPT
  61. #iptables -A FORWARD -i rmnet_usb0 -o usb0 -j ACCEPT
  62. #iptables -A FORWARD -i usb0 -o rmnet_usb0 -j ACCEPT
  63.  
  64. #get usb0 ipv6
  65. USB0_IP=$(ip addr show wlan0 | grep inet6)
  66.  
  67. dnsmasq --pid-file=/cache/usb_tether_dnsmasq.pid --interface=usb0 --bind-interfaces --bogus-priv --filterwin2k --no-resolv --domain-needed --server=8.8.8.8 --server=8.8.4.4 --cache-size=1000 --dhcp-range=192.168.22.2,192.168.22.3,255.255.255.0,192.168.22.255 --dhcp-lease-max=1 --dhcp-authoritative --dhcp-leasefile=/cache/usb_tether_dnsmasq.leases < /dev/null
  68. #dnsmasq --pid-file=/cache/usb_tether_dnsmasq.pid --interface=usb0 --bind-interfaces --bogus-priv --filterwin2k --no-resolv --domain-needed --server=2001:4860:4860::8888 --server=2001:4860:4860::8844 --cache-size=1000 --dhcp-range=::1,::200,constuctor:usb0 --dhcp-lease-max=1 --dhcp-authoritative --dhcp-leasefile=/cache/usb_tether_dnsmasq.leases < /dev/null
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement