Created
December 27, 2018 03:36
-
-
Save bizkut/3c24c66123103ad9773769a5a7f3881f to your computer and use it in GitHub Desktop.
Use your mobile's data on your pc without tethering.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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