|
@ -52,7 +52,7 @@ def get_table(key): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ThreadingTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer): |
|
|
class ThreadingTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer): |
|
|
pass |
|
|
allow_reuse_address = True |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Socks5Server(SocketServer.StreamRequestHandler): |
|
|
class Socks5Server(SocketServer.StreamRequestHandler): |
|
@ -65,14 +65,13 @@ class Socks5Server(SocketServer.StreamRequestHandler): |
|
|
data = sock.recv(4096) |
|
|
data = sock.recv(4096) |
|
|
if data <= 0: |
|
|
if data <= 0: |
|
|
break |
|
|
break |
|
|
if remote.send(self.encrypt(data)) <= 0: |
|
|
remote.sendall(self.encrypt(data)) |
|
|
break |
|
|
|
|
|
if remote in r: |
|
|
if remote in r: |
|
|
data = remote.recv(4096) |
|
|
data = remote.recv(4096) |
|
|
if data <= 0: |
|
|
if data <= 0: |
|
|
break |
|
|
break |
|
|
if sock.send(self.decrypt(data)) <= 0: |
|
|
sock.sendall(self.decrypt(data)) |
|
|
break |
|
|
|
|
|
finally: |
|
|
finally: |
|
|
sock.close() |
|
|
sock.close() |
|
|
remote.close() |
|
|
remote.close() |
|
@ -162,7 +161,6 @@ if __name__ == '__main__': |
|
|
decrypt_table = string.maketrans(encrypt_table, string.maketrans('', '')) |
|
|
decrypt_table = string.maketrans(encrypt_table, string.maketrans('', '')) |
|
|
try: |
|
|
try: |
|
|
server = ThreadingTCPServer(('', PORT), Socks5Server) |
|
|
server = ThreadingTCPServer(('', PORT), Socks5Server) |
|
|
server.allow_reuse_address = True |
|
|
|
|
|
logging.info("starting server at port %d ..." % PORT) |
|
|
logging.info("starting server at port %d ..." % PORT) |
|
|
server.serve_forever() |
|
|
server.serve_forever() |
|
|
except socket.error, e: |
|
|
except socket.error, e: |
|
|