Skip to content

Instantly share code, notes, and snippets.

@bizkut
Last active June 5, 2020 02:18
Show Gist options
  • Save bizkut/7c72d72a0fefb1058531709dd2f2d59d to your computer and use it in GitHub Desktop.
Save bizkut/7c72d72a0fefb1058531709dd2f2d59d to your computer and use it in GitHub Desktop.
Use your mobile phone's data on your pc without tethering. Doesn't need jailbreak or root.
#!/usr/bin/env python
import socket
import select
import threading
HOST = ''
PORT = 50007
# use https or socks5 and use the same protocol on pc
PROXYHOST = 'your proxy server'
PROXYPORT = 8080
def main():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(0)
while True:
conn, addr = s.accept()
print 'Connected by', addr, '#active', threading.active_count()
p = threading.Thread(target=tunnel, args=(conn,))
p.start()
s.close()
def tunnel(conn):
provy = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
provy.connect((PROXYHOST, PROXYPORT))
sent = threading.Thread(target=forwarder, args=(conn, provy))
recv = threading.Thread(target=forwarder, args=(provy, conn))
sent.start()
recv.start()
recv.join()
sent.join(10)
provy.close()
conn.close()
def forwarder(r_s, w_s):
try:
while True:
select.select([r_s], [], [])
data = r_s.recv(1024)
if not data: break
select.select([], [w_s], [])
w_s.sendall(data)
except Exception, e:
pass
r_s.close()
w_s.close()
if __name__ == '__main__':
main()
@bizkut
Copy link
Author

bizkut commented Dec 27, 2018

You need a public accessible proxy server.

  1. Create an ad hoc hotspot on your laptop
  2. Connect your phone to the laptop
  3. Manually edit the ip address, e.g. 10.0.0.1 on laptop and 10.0.0.2 on phone. use the same subnet of course
  4. Edit PROXYHOST and PROXYPORT to suit your proxy server.
  5. Run this script on the phone using any python app that support network connection
  6. Set the proxy setting on your pc using the phone's IP and port. default is 50007
  7. Profit
    make sure the phone's screen is stay active while using this. You can set the screen sleep to off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment