{"id":236394,"date":"2012-07-01T17:00:17","date_gmt":"2012-07-02T00:00:17","guid":{"rendered":"http:\/\/chinadigitaltimes.net\/chinese\/2012\/07\/%e7%bf%bb%e5%a2%99-%e7%94%a8python%e5%86%99%e7%9a%84socks5%e4%bb%a3%e7%90%86%e5%8f%8a%e5%85%b6%e5%88%86%e6%94%af\/"},"modified":"2012-07-01T17:00:17","modified_gmt":"2012-07-02T00:00:17","slug":"%e7%bf%bb%e5%a2%99-%e7%94%a8python%e5%86%99%e7%9a%84socks5%e4%bb%a3%e7%90%86%e5%8f%8a%e5%85%b6%e5%88%86%e6%94%af","status":"publish","type":"post","link":"https:\/\/chinadigitaltimes.net\/chinese\/236394.html","title":{"rendered":"\u7ffb\u5899 | \u7528Python\u5199\u7684socks5\u4ee3\u7406\u53ca\u5176\u5206\u652f"},"content":{"rendered":"<p>\u539f\u6587\uff1a<a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/igfw.net\/archives\/10294\">http:\/\/igfw.net\/archives\/10294<\/a><\/p>\n<div><\/div>\n<div>\n<p><a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/xiaoxia.org\/\">\u5c0f\u867e<\/a>\u662f\u4e2a\u597d\u540c\u5b66\uff0c\u4ee5\u524d\u4ecb\u7ecd\u8fc7\u5176\u7528Python\u5199\u7684VPN\u7a0b\u5e8f<a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/igfw.net\/archives\/7756\">udpip<\/a>\uff0c\u636e\u8bf4<a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/igfw.net\/archives\/10144\">WCProxy<\/a>\u6700\u521d\u4e5f\u662f\u5176\u7528Python\u5199\u6210\u7684\uff0c\u8fd9\u6b21\u8981\u4ecb\u7ecd\u7684\u662f\u5176\u7528Python\u5199\u7684socks5\u4ee3\u7406\u53ca\u5176\u5206\u652f\u3002<\/p>\n<p>\u597d\u5427\u4e0a<strong>Python\u5199\u7684socks5\u670d\u52a1\u5668\u7aef<\/strong>\u4ee3\u7801\uff08<a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/xiaoxia.org\/2011\/03\/29\/written-by-python-socks5-server\/\">\u6765\u6e90<\/a>\uff09\uff1a<\/p>\n<pre>import socket, sys, select, SocketServer, struct, time \u00a0    \u00a0\u00a0\u00a0 class ThreadingTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer): pass \u00a0  \u00a0\u00a0\u00a0 class Socks5Server(SocketServer.StreamRequestHandler): \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 def handle_tcp(self, sock, remote): \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 fdset = [sock, remote] \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 while True: \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 r, w, e = select.select(fdset, [], []) \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if sock in r: \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if remote.send(sock.recv(4096)) <= 0: break \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if remote in r: \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if sock.send(remote.recv(4096)) <= 0: break \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 def handle(self): \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 try: \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 print &#39;socks connection from &#39;, self.client_address \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sock = self.connection \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # 1. Version \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sock.recv(262) \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sock.send(b\"x05x00\"); \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # 2. Request \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 data = self.rfile.read(4) \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 mode = ord(data[1]) \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 addrtype = ord(data[3]) \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if addrtype == 1:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # IPv4 \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 addr = socket.inet_ntoa(self.rfile.read(4)) \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 elif addrtype == 3:\u00a0\u00a0\u00a0\u00a0 # Domain name \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 addr = self.rfile.read(ord(sock.recv(1)[0])) \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 port = struct.unpack(&#39;>H&#39;, self.rfile.read(2)) \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 reply = b\"x05x00x00x01\" \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 try: \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if mode == 1:\u00a0 # 1. Tcp connect \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 remote = socket.socket(socket.AF_INET, socket.SOCK_STREAM) \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 remote.connect((addr, port[0])) \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 print &#39;Tcp connect to&#39;, addr, port[0] \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 else: \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 reply = b\"x05x07x00x01\" # Command not supported \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 local = remote.getsockname() \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 reply += socket.inet_aton(local[0]) + struct.pack(\">H\", local[1]) \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 except socket.error: \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # Connection refused \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 reply = &#39;x05x05x00x01x00x00x00x00x00x00&#39; \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sock.send(reply) \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # 3. Transfering \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if reply[1] == &#39;x00&#39;:\u00a0 # Success \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if mode == 1:\u00a0\u00a0\u00a0 # 1. Tcp connect \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 self.handle_tcp(sock, remote) \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 except socket.error: \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 print &#39;socket error&#39; \u00a0  \u00a0\u00a0\u00a0 def main(): \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 server = ThreadingTCPServer((&#39;&#39;, 1080), Socks5Server) \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 server.serve_forever() \u00a0  \u00a0\u00a0\u00a0 if __name__ == &#39;__main__&#39;: \u00a0  \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 main()<\/pre>\n<p>\u76f4\u63a5\u8fd0\u884c\u8fd9\u4e2a\u7a0b\u5e8f\u5c31\u7ed9\u672c\u673a\u5efa\u7acb\u4e86\u4e00\u4e2asocks5\u7684\u4ee3\u7406\u670d\u52a1\u5668\uff08\u9700\u8981Python2.6\u4ee5\u4e0a\u7248\u672c\u624d\u80fd\u8fd0\u884c\uff09\u3002<\/p>\n<p>  \u5c31\u8fd9\u4e48\u7b80\u5355\uff0c\u65e0\u8bba\u4f60\u770b\u61c2\u6ca1\u770b\u61c2\uff0c\u53cd\u6b63\u6211\u662f\u4e0d\u61c2Python\u4ee3\u7801\u3002<\/p>\n<p>\u597d\u5427\u90a3\u53d1\u4e00\u4e2a\u67d0\u4eba\u81ea\u7528\u4e86\u4e00\u5e74\u591a\u7684\u7ffb\u5899\u5de5\u5177 shadowsocks \u5427\uff0c\u8fd9\u4e2ashadowsocks\u5c31\u662f\u6839\u636e\u4e0a\u9762\u7684\u4ee3\u7801\u4fee\u6539\u7684\uff0c\u8fd9\u4e2a\u7528 Python \u5199\u7684 socks \u52a0\u5bc6\u4ee3\u7406\uff0c\u52a0\u5bc6\u65b9\u6cd5\u5f88\u7b80\u5355\uff0c\u4e0d\u8fc7\u6b3a\u9a97 GFW \u8db3\u591f\u4e86\u3002 shadowsocks\u4f5c\u8005\u8bf4\uff1b\u201c\u5f53\u521d\u6fc0\u53d1\u6211\u5199\u8fd9\u4e2a\u4e1c\u897f\u7684\u539f\u56e0\u662f ssh tunnel \u5bb9\u6613\u65ad\uff0c\u6bcf\u6b21\u91cd\u8fde\u4f1a\u5361\u4e00\u6bb5\u65f6\u95f4\uff0c\u5e76\u4e14\u5e76\u53d1\u80fd\u529b\u6709\u9650\u3002\u4e8e\u662f\u7528\u666e\u901a\u7684 socket server\uff0c\u6765\u4e00\u4e2a\u8fde\u63a5\u5efa\u4e00\u4e2a\u8fde\u63a5\u3002\u5230\u73b0\u5728\u7528\u4e86\u4e00\u5e74\u591a\uff0c\u611f\u89c9\u633a\u7a33\u5b9a\uff0c\u4e0d\u5982\u53d1\u5e03\u51fa\u6765\u5427\u3002<br \/>  \u201d\u3002<\/p>\n<p><strong>shadowsocks\u9879\u76ee\u5730\u5740<\/strong>\uff1a<a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/github.com\/clowwindy\/shadowsocks\">https:\/\/github.com\/clowwindy\/shadowsocks<\/a><\/p>\n<p>\u4f7f\u7528\u65b9\u6cd5\uff1a<\/p>\n<p>Put\u00a0<code>server.py<\/code>\u00a0on your server. Edit\u00a0<code>server.py<\/code>, change the following values:<\/p>\n<pre><code>PORT server port   KEY a password to identify clients <\/code><\/pre>\n<p>Run\u00a0<code>python server.py<\/code>\u00a0on your server. To run it in the background, run\u00a0<code>setsid python server.py<\/code>.<\/p>\n<p>Put\u00a0<code>local.py<\/code>\u00a0on your client machine. Edit\u00a0<code>local.py<\/code>, change these values:<\/p>\n<pre><code>SERVER your server ip or hostname   REMOTE_PORT server port PORT local port   KEY a password, it must be the same as the password of your server <\/code><\/pre>\n<p>Run\u00a0<code>python local.py<\/code>\u00a0on your client machine.<\/p>\n<p>Change proxy settings of your browser into<\/p>\n<pre><code>SOCKS5 127.0.0.1:PORT <\/code><\/pre>\n<p>\u6211\u6ca1\u6709\u6d4b\u8bd5\u8fc7\u8fd9\u4e2a\u7a0b\u5e8f\uff0c\u6211\u6d4b\u8bd5\u7684\u662fbalan-proxy\u7a0b\u5e8f\u3002balan-proxy\u7a0b\u5e8ffork\u81eashadowsocks\u3002\u6ca1\u4fee\u6539\u4ec0\u4e48\uff0c\u5c31\u7528\u751f\u6210\u5668\u5faa\u73af\u8fd4\u56de\u670d\u52a1\u5668\u5730\u5740\uff0c\u589e\u52a0\u5bf9\u591a\u4e2a\u670d\u52a1\u7aef\u7684\u652f\u6301\uff0c\u5982\u679c\u5728\u9650\u5236\u5e26\u5bbd\u7684\u5185\u7f51\u4f7f\u7528\uff0c\u53ef\u8fbe\u5230\u591a\u500d\u5e26\u5bbd\u7684\u6548\u679c\u3002\u5728\u4e0b\u8f7dhttp\u8d44\u6e90\uff0c\u53ca\u64ad\u653e\u5728\u7ebf\u89c6\u9891\u65f6\u6709\u663e\u8457\u52a0\u901f\u529f\u80fd\u3002<\/p>\n<p><strong>balan-proxy\u9879\u76ee\u5730\u5740<\/strong>\uff1a<a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/github.com\/lerry\/balan-proxy\">https:\/\/github.com\/lerry\/balan-proxy<\/a><\/p>\n<p>  \u589e\u52a0\u81ea\u5b9a\u4e49\u670d\u52a1\u5668\u5217\u8868\u652f\u6301\uff0c\u8bf7\u5c06\u670d\u52a1\u5668\u5730\u5740\u5217\u8868\u653e\u5728\u540c\u6587\u4ef6\u5939\u4e0b\uff0c\u6587\u4ef6\u540d\uff1a list.txt \u683c\u5f0f:<br \/><a rel=\"nofollow\" target=\"_blank\" href=\"http:\/\/8.8.8.8:8499\">8.8.8.8:8499<\/a><br \/><a rel=\"nofollow\" target=\"_blank\" href=\"http:\/\/4.4.4.4:8499\">4.4.4.4:8499<\/a><br \/>#<a rel=\"nofollow\" target=\"_blank\" href=\"http:\/\/1.1.1.1:8849\">1.1.1.1:8849<\/a><br \/>\u6682\u65f6\u4e0d\u4f7f\u7528\u7684\u670d\u52a1\u5668\u5730\u5740\u53ef\u4f7f\u7528#\u6ce8\u91ca<\/p>\n<p>\u7528\u6cd5\u548cshadowsocks\u4e00\u6837\uff08 \u88c5gevent\uff0c\u7136\u540e\u5728\u542f\u52a8server.py\uff0c\u80fd\u7701\u4e0b\u4e00\u4e9b\u5185\u5b58\uff09\u3002<\/p>\n<p>  \u4e0d\u8fc7\u4e0a\u9762\u4ee3\u7406\u52a0\u5bc6\u7b80\u5355\uff0c\u5982\u679c\u8981\u9ad8\u5f3a\u5ea6\u7684\u52a0\u5bc6\u53ef\u4ee5\u8003\u8651\u6362\u6210\u4e24\u8fb9\u7528ssl\u6765\u901a\u4fe1\uff0c\u8fd9\u5c31\u6709\u4e86sockstunnel\uff0csockstunnel\u662f\u4e00\u4e2a\u4f7f\u7528ssl\u52a0\u5bc6\u96a7\u9053\u7684\u7b80\u5355 socks5\u670d\u52a1\u5668\uff08shadowsocks\u4e5f\u5728\u6d4b\u8bd5\u66f4\u5f3a\u7684\u52a0\u5bc6\u65b9\u5f0f\uff09\u3002<\/p>\n<p><strong>sockstunnel\u9879\u76ee\u5730\u5740<\/strong>\uff1a<a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/github.com\/wynemo\/sockstunnel\">https:\/\/github.com\/wynemo\/sockstunnel<\/a><\/p>\n<p>\u5728\u670d\u52a1\u5668\u4e0a\uff0c\u4f7f\u7528 openssl \u751f\u6210\u60a8\u7684\u5bc6\u94a5\u548c\u8bc1\u4e66\u6587\u4ef6\u7684\u65b9\u6cd5<\/p>\n<pre><code>openssl genrsa -out privkey.pem 2048   openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095<\/code><\/pre>\n<p>\u4f5c\u8005\u8bf4\u5176\u5728server:ubuntu 11.10 x64 python2.7 \/client:windows7 python 2.7.3,ubuntu 11.10 python 2.7.2\u4e0b\u6d4b\u8bd5\u6210\u529f\uff0c\u6709\u5174\u8da3\u7684\u53ef\u4ee5\u8bd5\u8bd5\u3002<\/p>\n<p>\u9664\u4e86\u52a0\u5bc6\u95ee\u9898\uff0c\u8fd8\u6709\u4eba\u63d0\u51fa\u4e86IPv6\u652f\u6301\u95ee\u9898\uff0c\u4e8e\u662fshadowsocks\u4f5c\u8005\u52a0\u4e86\u4e00\u4e2a\u5b9e\u9a8c\u6027\u7684 IPv6 branch\uff0cServer \u662f IPv6 \u5730\u5740\uff0c\u56e0\u4e3a\u548c IPv4 \u4e0d\u517c\u5bb9\uff0c\u6240\u4ee5\u6682\u65f6\u6ca1\u5408\u5e76\u3002<\/p>\n<p>  <strong>IPv6 branch\u9879\u76ee\u5730\u5740<\/strong>\uff1a<a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/github.com\/clowwindy\/shadowsocks\/tree\/ipv6\">https:\/\/github.com\/clowwindy\/shadowsocks\/tree\/ipv6<\/a><\/p>\n<p>  shadowsocks\u4f5c\u8005\u6298\u817e\u5b8cPython\u7248\u540e\u53c8\u628a\u76ee\u5149\u7784\u5411\u4e86node.js\uff0c\u8fd9\u5c31\u6709\u4e86\u52a0\u5bc6\u4ee3\u7406 shadowsocks node.js \u7248\u3002\u4f5c\u8005\u8bf4\u52a0\u5bc6\u4ee3\u7406 shadowsocks node.js \u7248\u7ecf\u8fc7\u4e00\u4e2a\u591a\u6708\u7684\u6539\u8fdb\u73b0\u5728\u53ef\u4ee5\u5728 1000 \u5e76\u53d1\uff0c500 QPS \u4e0b\u7a33\u5b9a\u5de5\u4f5c\u3002\u73b0\u5728\u7528\u5728\u4e00\u4e2a\u9879\u76ee\u4e2d\uff0c\u6bcf\u5929\u901a\u8fc7\u4e0a\u767e GB \u6d41\u91cf\u3002<\/p>\n<p>  <strong>shadowsocks-nodejs\u9879\u76ee\u5730\u5740<\/strong>\uff1a<a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/github.com\/clowwindy\/shadowsocks-nodejs\">https:\/\/github.com\/clowwindy\/shadowsocks-nodejs<\/a><\/p>\n<p>  \u548c\u539f Python \u7248\u76f8\u6bd4\u4f18\u52bf\uff1a<br \/>1. \u4e0d\u4f1a\u5927\u91cf\u521b\u5efa\u7ebf\u7a0b\uff0cVSZ \u4f7f\u7528\u5f88\u5c11\uff0c\u9002\u5408 OpenVZ\u3002<br \/>2. \u652f\u6301\u66f4\u5927\u5e76\u53d1\u3002\u56e0\u4e3a Python \u7248\u7528\u7684\u662f select()\uff0cfd > 1024 \u7684\u65f6\u5019\u5c31\u6302\u4e86\u3002<\/p>\n<p>\u7f3a\u70b9\uff1a<br \/>\u4e0b\u8f7d\u5927\u6587\u4ef6\u65f6\u5185\u5b58\u5360\u7528\u5cf0\u503c\u4f1a\u8fbe\u5230\u51e0\u5341 MB\uff0c\u6000\u7591\u4e0e V8 \u7684 GC \u7b56\u7565\u6709\u5173\u3002(<a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/www.v2ex.com\/t\/37359\">\u53c2\u8003<\/a>)<br \/>  \u5f53\u7136 Python \u7248\u4e5f\u53ef\u4ee5\u6539\u7528\u975e\u963b\u585e\u6a21\u578b\uff0c\u4e0d\u8fc7\u5199\u8d77\u6765\u6bd4 nodejs \u9ebb\u70e6\u5c31\u662f\u4e86\u3002\u6b22\u8fce\u6709\u5174\u8da3\u7684\u7ae5\u978b\u505a\u8fd9\u6837\u7684\u5c1d\u8bd5 :)<\/p>\n<p>\u8bf4\u660e\uff1a<br \/>\u5982\u679c\u90fd\u5347\u5230\u6700\u65b0\u7248\uff0cPython \u7248\u4e0e node.js \u7248\u7684\u534f\u8bae\u662f\u4e92\u76f8\u517c\u5bb9\u7684\u3002\u5373\u53ef\u4ee5\u7528 python client + node.js server\u3002<br \/>  \u53e6\u5916\u611f\u53f9 V8 \u7684\u6027\u80fd\u786e\u5b9e\u5f88\u597d\uff0c\u57fa\u672c\u76f8\u540c\u7684\u8ba1\u7b97\u5bc6\u7801\u8868\u8fc7\u7a0b\uff0c\u7eaf js \u5b9e\u73b0\u6bd4\u7eaf Python \u5b9e\u73b0\u5feb\u4e86\u51e0\u5341\u500d\u3002<\/p>\n<p>\u4f7f\u7528\u65b9\u6cd5\uff1a<\/p>\n<p lang=\"zh-chs\">  Edit\u00a0<code>config.json<\/code>, change the following values:<\/p>\n<pre><code>server your server ip or hostname   server_port server port   local_port local port   password a password used to encrypt transfer   timeout in seconds <\/code><\/pre>\n<p>Put all the files on your server. Run\u00a0<code>node server.js<\/code>\u00a0on your server. To run it in the background, run\u00a0<code>setsid node server.js<\/code>.<\/p>\n<p>Put all the files on your client machine. Run\u00a0<code>node local.js<\/code>\u00a0on your client machine.<\/p>\n<p lang=\"zh-chs\">  Change proxy settings of your browser into<\/p>\n<pre><code>SOCKS5 127.0.0.1:local_port <\/code><\/pre>\n<p>  \u53e6\u5916\u4f5c\u8005\u8fd8\u5c06\u591a server \u529f\u80fd\u52a0\u5230\u4e00\u4e2a\u65b0\u5206\u652f\u91cc\u4e86\u3002<\/p>\n<p><strong>multi-server branc\u9879\u76ee\u5730\u5740<\/strong>\uff1a<a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/github.com\/clowwindy\/shadowsocks-nodejs\/tree\/multi-server\">https:\/\/github.com\/clowwindy\/shadowsocks-nodejs\/tree\/multi-server<\/a><\/p>\n<p>50\u591a\u884c\u4ee3\u7801\u5f15\u8d77\u4e86\u8fd9\u8bb8\u591a\u6545\u4e8b\uff0c\u7ec8\u7a76\u4f7f\u7528\u8d77\u6765\u8fd8\u662f\u8981\u6bd4ssh\u4ee3\u7406\u901f\u5ea6\u5feb\uff0c\u6709VPS\u7684\u540c\u5b66\u53ef\u4ee5\u8bd5\u8bd5\u5566\u3002<\/p>\n<p>  \u53e6\u5916\u4ee5\u524d\u8bf4\u8fc7goagent\u5728<a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/repo.or.cz\/w\/goagent.git\/snapshot\/13ce2fd7a5ff624fe1cfc9e8108208e30e79e1e9.zip\">1.9.1a2<\/a>\u6d4b\u8bd5\u7248\u672c\u4e2d\u52a0\u5165\u4f7f\u7528ssl\u52a0\u5bc6\u72ec\u7acb\u4e3b\u673a\u4e0a\u7684wsgi.py\uff08\u4f7f\u7528\u65b9\u6cd5:python wsgi.py 443 -ssl \uff09\uff0c\u8fd9\u4e2a\u548c\u4e0a\u9762\u4ecb\u7ecd\u7684\u4e5f\u662f\u6b8a\u9014\u540c\u5f52\uff0c\u4e0d\u8fc7goagent\u8c8c\u4f3c\u4e5f\u5f00\u59cb\u72ec\u7acb\u4e3b\u673a\u4e0a\u7684socks5\u4ee3\u7406\u4e86\u3002<\/p>\n<p><strong>\u672c\u6587\u539f\u59cb\u5730\u5740<\/strong>\uff1a<a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/igfw.net\/archives\/10294\">http:\/\/igfw.net\/archives\/10294<\/a><\/p>\n<\/p><\/div>\n<div>\u8bf7\u70b9\u51fb<a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/mycdt4.info\/chinese\/\">https:\/\/mycdt4.info\/chinese\/<\/a>\uff0c\u7a7f\u5899\u8bbf\u95ee\u300a\u4e2d\u56fd\u6570\u5b57\u65f6\u4ee3\u300b\u3002\u300a\u4e2d\u56fd\u6570\u5b57\u65f6\u4ee3\u300b\u5f00\u901aIPv6\uff0c\u6b22\u8fce\u7a7f\u5899\u9605\u8bfb\u3002\u7ffb\u8d8a\u9632\u706b\u957f\u57ce\uff0c\u4f60\u53ef\u4ee5\u5230\u8fbe\u4e16\u754c\u4e0a\u7684\u6bcf\u4e00\u4e2a\u89d2\u843d\u3002\uff08Across the Great Firewall, you can reach every corner in the world.\uff09\u7ffb\u5899\u5229\u5668\u8d5b\u98ce3\u4e0b\u8f7d\u5730\u5740\uff1a<a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/dld.bz\/caonima326\n\n\"> http:\/\/dld.bz\/caonima326<\/p>\n<p><\/a>\uff0c<a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/dld.bz\/caonima745\">http:\/\/dld.bz\/caonima745<\/a><img loading=\"lazy\" decoding=\"async\" width=\"1\" height=\"1\" src=\"https:\/\/blogger.googleusercontent.com\/tracker\/5500297126185736776-6553744339627983047?l=www.chinagfw.org\" alt=\"\" \/><\/div>\n<\/p>\n<p><small>\u672c\u6587\u7531\u81ea\u52a8\u805a\u5408\u7a0b\u5e8f\u53d6\u81ea\u7f51\u7edc\uff0c\u5185\u5bb9\u548c\u89c2\u70b9\u4e0d\u4ee3\u8868\u6570\u5b57\u65f6\u4ee3\u7acb\u573a<\/small><\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/docs.google.com\/spreadsheet\/embeddedform?hl=zh-CN&#038;formkey=dGRpN3FrVThuMFFsZHBZcmNGLW94dEE6MQ\" width=\"510\" height=\"328\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\">Loading&#8230;<\/iframe><\/p>\n<form method=\"POST\" action=\"http:\/\/chinadigitaltimes.us4.list-manage.com\/subscribe\/post?u=17daa75df533f6c6ff72e51ab&#038;id=b4fd4ae247\">\n\u5b9a\u671f\u83b7\u5f97\u7ffb\u5899\u4fe1\u606f\uff1f<a href=\"http:\/\/eepurl.com\/mstlf\" target=\"_blank\" rel=\"noopener\">\u8bf7\u7535\u90ae\u8ba2\u9605\u6570\u5b57\u65f6\u4ee3<\/a><br \/>\n <br \/><input type=\"email\" value=\"\" name=\"EMAIL\" id=\"mce-EMAIL_in_post\" size=\"25\" style=\"display:block;\" placeholder=\"\u8bf7\u8f93\u5165\u60a8\u7684\u90ae\u4ef6\u5730\u5740\" required><br \/>\n\t<input type=\"submit\" value=\"\u70b9\u51fb\u8ba2\u9605\" name=\"subscribe\" style=\"height: 20px;\" id=\"in_post_subscribe\"><br \/>\n<\/form>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\uff1a http:\/\/igfw.net\/archives\/10294 \u5c0f\u867e \u662f\u4e2a\u597d\u540c\u5b66\uff0c\u4ee5\u524d\u4ecb\u7ecd\u8fc7\u5176\u7528Python\u5199\u7684VPN\u7a0b\u5e8f udpip \uff0c\u636e\u8bf4 WCProxy \u6700\u521d\u4e5f\u662f\u5176\u7528Python\u5199\u6210\u7684\uff0c\u8fd9\u6b21\u8981\u4ecb\u7ecd\u7684\u662f\u5176\u7528Python\u5199\u7684socks5\u4ee3\u7406\u53ca\u5176\u5206\u652f\u3002 \u597d\u5427\u4e0a Python\u5199\u7684socks5\u670d\u52a1\u5668\u7aef \u4ee3\u7801\uff08 \u6765\u6e90 \uff09\uff1a import socket, sys, select, SocketServer, struct, time \u00a0 \u00a0\u00a0\u00a0 class ThreadingTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer): pass \u00a0 \u00a0\u00a0\u00a0 class Socks5Server(SocketServer.StreamRequestHandler): \u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 def handle_tcp(self, sock, remote): \u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 fdset = [sock, remote] \u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 while True: \u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 r, w, e = select.select(fdset, [], []) \u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if sock in r: \u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if remote.send(sock.recv(4096)) 1024 \u7684\u65f6\u5019\u5c31\u6302\u4e86\u3002 \u7f3a\u70b9\uff1a \u4e0b\u8f7d\u5927\u6587\u4ef6\u65f6\u5185\u5b58\u5360\u7528\u5cf0\u503c\u4f1a\u8fbe\u5230\u51e0\u5341 MB\uff0c\u6000\u7591\u4e0e V8 \u7684 GC \u7b56\u7565\u6709\u5173\u3002( \u53c2\u8003 ) \u5f53\u7136 Python \u7248\u4e5f\u53ef\u4ee5\u6539\u7528\u975e\u963b\u585e\u6a21\u578b\uff0c\u4e0d\u8fc7\u5199\u8d77\u6765\u6bd4 nodejs \u9ebb\u70e6\u5c31\u662f\u4e86\u3002\u6b22\u8fce\u6709\u5174\u8da3\u7684\u7ae5\u978b\u505a\u8fd9\u6837\u7684\u5c1d\u8bd5 :) \u8bf4\u660e\uff1a \u5982\u679c\u90fd\u5347\u5230\u6700\u65b0\u7248\uff0cPython \u7248\u4e0e node.js \u7248\u7684\u534f\u8bae\u662f\u4e92\u76f8\u517c\u5bb9\u7684\u3002\u5373\u53ef\u4ee5\u7528 python client + node.js server\u3002 \u53e6\u5916\u611f\u53f9 V8 \u7684\u6027\u80fd\u786e\u5b9e\u5f88\u597d\uff0c\u57fa\u672c\u76f8\u540c\u7684\u8ba1\u7b97\u5bc6\u7801\u8868\u8fc7\u7a0b\uff0c\u7eaf js \u5b9e\u73b0\u6bd4\u7eaf Python \u5b9e\u73b0\u5feb\u4e86\u51e0\u5341\u500d\u3002 \u4f7f\u7528\u65b9\u6cd5\uff1a Edit\u00a0 config.json , change the following values: server your server ip or hostname server_port server port local_port local port password a password used to encrypt transfer timeout in seconds Put all the files on your server. Run\u00a0 node server.js \u00a0on your server. To run it in the background, run\u00a0 setsid node server.js . Put all the files on your client machine. Run\u00a0 node local.js \u00a0on your client machine<\/p>\n","protected":false},"author":1005,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","ampforwp-amp-on-off":"","home_featured":"","footnotes":"","_links_to":"","_links_to_target":""},"categories":[15300],"tags":[7775,8795],"class_list":["post-236394","post","type-post","status-publish","format-standard","hentry","category-15300","tag-gfw","tag-8795","et-doesnt-have-format-content","et_post_format-et-post-format-standard"],"_links":{"self":[{"href":"https:\/\/chinadigitaltimes.net\/chinese\/wp-json\/wp\/v2\/posts\/236394","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chinadigitaltimes.net\/chinese\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chinadigitaltimes.net\/chinese\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chinadigitaltimes.net\/chinese\/wp-json\/wp\/v2\/users\/1005"}],"replies":[{"embeddable":true,"href":"https:\/\/chinadigitaltimes.net\/chinese\/wp-json\/wp\/v2\/comments?post=236394"}],"version-history":[{"count":0,"href":"https:\/\/chinadigitaltimes.net\/chinese\/wp-json\/wp\/v2\/posts\/236394\/revisions"}],"wp:attachment":[{"href":"https:\/\/chinadigitaltimes.net\/chinese\/wp-json\/wp\/v2\/media?parent=236394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chinadigitaltimes.net\/chinese\/wp-json\/wp\/v2\/categories?post=236394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chinadigitaltimes.net\/chinese\/wp-json\/wp\/v2\/tags?post=236394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}