Skip to content

Instantly share code, notes, and snippets.

@harimau99
Forked from bizkut/mobile_hotspot.py
Created December 27, 2018 10:15
Show Gist options
  • Save harimau99/62bdee920b49936ead845f9bfea5401b to your computer and use it in GitHub Desktop.
Save harimau99/62bdee920b49936ead845f9bfea5401b 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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment