|
@ -52,7 +52,7 @@ my_lock = threading.Lock() |
|
|
def lock_print(msg): |
|
|
def lock_print(msg): |
|
|
my_lock.acquire() |
|
|
my_lock.acquire() |
|
|
try: |
|
|
try: |
|
|
print "[%s]%s" % (time.ctime(), msg) |
|
|
print "[%s] %s" % (time.ctime(), msg) |
|
|
finally: |
|
|
finally: |
|
|
my_lock.release() |
|
|
my_lock.release() |
|
|
|
|
|
|
|
@ -69,6 +69,7 @@ class Socks5Server(SocketServer.StreamRequestHandler): |
|
|
return data.translate(decrypt_table) |
|
|
return data.translate(decrypt_table) |
|
|
|
|
|
|
|
|
def handle_tcp(self, sock, remote): |
|
|
def handle_tcp(self, sock, remote): |
|
|
|
|
|
try: |
|
|
fdset = [sock, remote] |
|
|
fdset = [sock, remote] |
|
|
counter = 0 |
|
|
counter = 0 |
|
|
while True: |
|
|
while True: |
|
@ -77,20 +78,24 @@ class Socks5Server(SocketServer.StreamRequestHandler): |
|
|
r_data = sock.recv(4096) |
|
|
r_data = sock.recv(4096) |
|
|
if counter == 1: |
|
|
if counter == 1: |
|
|
try: |
|
|
try: |
|
|
lock_print("Connecting " + r_data[5:5 + ord(r_data[4])]) |
|
|
lock_print( |
|
|
|
|
|
"Connecting " + r_data[5:5 + ord(r_data[4])]) |
|
|
except Exception: |
|
|
except Exception: |
|
|
pass |
|
|
pass |
|
|
if counter < 2: |
|
|
if counter < 2: |
|
|
counter += 1 |
|
|
counter += 1 |
|
|
if remote.send(self.encrypt(r_data)) <= 0: break |
|
|
if remote.send(self.encrypt(r_data)) <= 0: |
|
|
|
|
|
break |
|
|
if remote in r: |
|
|
if remote in r: |
|
|
if sock.send(self.decrypt(remote.recv(4096))) <= 0: |
|
|
if sock.send(self.decrypt(remote.recv(4096))) <= 0: |
|
|
break |
|
|
break |
|
|
|
|
|
finally: |
|
|
|
|
|
remote.close() |
|
|
|
|
|
|
|
|
def handle(self): |
|
|
def handle(self): |
|
|
try: |
|
|
try: |
|
|
sock = self.connection |
|
|
sock = self.connection |
|
|
remote = socket.socket() |
|
|
remote = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
|
remote.connect((SERVER, REMOTE_PORT)) |
|
|
remote.connect((SERVER, REMOTE_PORT)) |
|
|
self.handle_tcp(sock, remote) |
|
|
self.handle_tcp(sock, remote) |
|
|
except socket.error: |
|
|
except socket.error: |
|
|