Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/python2
- # fakehtcnat.py, version 2.1 by invik
- import io,socket,subprocess,sys, time
- dhcpfile = "/var/state/dhclient/dhclient.leases"
- srvrstr = "option dhcp-server-identifier"
- print "Waiting for the phone to come up...\n"
- # To send things to trash
- o = file("/dev/null","w")
- # Wait up to 10 seconds waiting for usb0 to show up
- i=0
- while (i<10):
- rtn = subprocess.call(["/sbin/ifconfig","usb0"], stdout = o, stderr=o)
- if (not rtn): break
- time.sleep(1)
- i += 1
- if (rtn):
- print "ERROR: Timeout waiting for usb0 to come up\n"
- sys.exit(1)
- # Get a dhcp address
- rtn = subprocess.call(["sudo","/usr/sbin/dhclient","usb0"], stdout = o, stderr=o)
- if (rtn):
- print "ERROR: not able to get IP from DHCP\n"
- sys.exit(2)
- # Check that usb0 is up and has IP
- pipeout = subprocess.Popen(["/sbin/ifconfig","usb0"],stdout = subprocess.PIPE,stderr=subprocess.STDOUT)
- rtn = pipeout.communicate()[0].find("192.168.99")
- if (rtn<0):
- print "ERROR: usb0 is not up or has not IP\n"
- sys.exit(3)
- # Read dhcp lease file and get phone's address
- f = open(dhcpfile,'r')
- d = f.read()
- u = d.rfind("interface \"usb0\"")
- l = d.find(srvrstr,u)
- e = d.find(';',l)
- host = d[l+len(srvrstr)+1:e]
- print "Phone is up at IP = " + host + "\n"
- # Send activation command to phone
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.setsockopt(socket.SOL_IP, socket.IP_TTL, 128 )
- s.connect((host, 6000))
- s.sendall(chr(0) + chr(2) + chr(0) + chr(0))
- s.close()
- print "Connection signal sent.\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement