CLOWWINDY最早的SHADOWSOCKS(此版已被作者CLOWWINDY删除),不过它有一个FORK版:balan-proxy (https://github.com/lerry/balan-proxy/)
登录你的vps,
git clone https://github.com/lerry/balan-proxy/
cd balan-proxy
编辑balan-proxy目录里的server.py如下:
...
PORT = 8499 (这个是balan-proxy的端口号,保持默认的8499,不必修改)
KEY = "你自行设置的一个字符串" (注意:这里的引号不可缺少。需跟本地的local.py里的KEY值一致)
...
然后运行命令:python server.py
此命令是运行在前台的。我们可以利用systemd把它运行为service:
nano /etc/systemd/system/balan-proxy.service
cat /etc/systemd/system/balan-proxy.service
[Unit]
After=network.target
[Service]
ExecStart=/usr/bin/python /root/balan-proxy/server.py
Restart=always
[Install]
WantedBy=multi-user.target
然后运行:
systemctl start balan-proxy
systemctl enable balan-proxy
服务器端搭建完成。
(当然你的vps需先安装python:apt-get install python -y或yum install python -y)
回到本地linux桌面系统机器,
下载源码:https://github.com/lerry/balan-proxy/archive/master.zip。
解压,进入解压出来的目录,编辑里面的local.py文件如下:
...
SERVERS = [
('你的vps的ip', 8499),
]
...
PORT = 10802 #这个是要设置的本地端口,你可以修改它为其他端口。
KEY = "你自行设置的一个字符串" (注意:这里的引号不可缺少。这个KEY值需跟你vps上设置的KEY值一致)
...
运行nohup python local.py > /dev/null &
然后设置你的浏览器的socks5代理为127.0.0.1,端口为10802,即可翻墙。
如果你的本地机器为mac.
git clone https://github.com/lerry/balan-proxy
cd balan-proxy
编辑里面的local.py文件如下:
...
SERVERS = [
('你的vps的ip', 8499),
]
...
PORT = 10802 #这个是要设置的本地端口,你可以修改它为其他端口。
KEY = "你自行设置的一个字符串" (注意:这里的引号不可缺少。这个KEY值需跟你vps上设置的KEY值一致)
...
然后,运行python local.py
(不要关闭该terminal窗口)
然后设置你的浏览器的socks5代理为127.0.0.1,端口为10802,即可翻墙。
在mac上,可通过launchd实现开机自运行命令:python local.py,操作流程如下:
cd ~/Library/LaunchAgents/
nano com.balan-proxy.plist
内容为:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.balan-proxy</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/python</string>
<string>~/balan-proxy/local.py</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
然后运行launchctl load com.balan-proxy.plist
这样,即可实现开机自运行命令:python local.py
如果你的本地机器为windows,
则在你的本地windows机器上安装python2.7.3环境: http://www.python.org/ftp/python/2.7.3/python-2.7.3.msi,python2.7.2有问题,建议卸载python2.7.2,安装python2.7.3,然后就可以运行local.py(即双击local.py),会弹出一个 dos窗口,不要关闭该窗口。然后设置你的浏览器的socks5代理为127.0.0.1,端口为10802,即可翻墙.
项目地址:https://github.com/lerry/balan-proxy
为防止balan-proxy的作者删除源码,特在此把local.py文件的内容和server.py文件的内容保存如下。
附录:
local.py文件的内容:
| #!/usr/bin/env python | |
| # Copyright (c) 2012 clowwindy | |
| # | |
| # Permission is hereby granted, free of charge, to any person obtaining a copy | |
| # of this software and associated documentation files (the "Software"), to deal | |
| # in the Software without restriction, including without limitation the rights | |
| # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| # copies of the Software, and to permit persons to whom the Software is | |
| # furnished to do so, subject to the following conditions: | |
| # | |
| # The above copyright notice and this permission notice shall be included in | |
| # all copies or substantial portions of the Software. | |
| # | |
| # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
| # SOFTWARE. | |
| import os | |
| SERVERS = [ | |
| ('xxx.xxx.xx.11', 8499), | |
| ] | |
| if os.path.exists('list.txt'): | |
| data = open('list.txt').readlines() | |
| SERVERS = [] | |
| item = (i.split(':') for i in data if ':' '#' not in i) | |
| while 1: | |
| try: | |
| i = item.next() | |
| except: | |
| break | |
| SERVERS.append((i[0], int(i[1]))) | |
| PORT = 1080 | |
| KEY = "foobar!" | |
| import sys | |
| import socket | |
| import select | |
| import string | |
| import struct | |
| import hashlib | |
| import threading | |
| import time | |
| import SocketServer | |
| def get_server(): | |
| servers = SERVERS | |
| while 1: | |
| for i in servers: | |
| yield i | |
| server = get_server() | |
| def get_table(key): | |
| m = hashlib.md5() | |
| m.update(key) | |
| s = m.digest() | |
| (a, b) = struct.unpack('<QQ', s) | |
| table = [c for c in string.maketrans('', '')] | |
| for i in xrange(1, 1024): | |
| table.sort(lambda x, y: int(a % (ord(x) + i) - a % (ord(y) + i))) | |
| return table | |
| encrypt_table = ''.join(get_table(KEY)) | |
| decrypt_table = string.maketrans(encrypt_table, string.maketrans('', '')) | |
| my_lock = threading.Lock() | |
| def lock_print(msg): | |
| my_lock.acquire() | |
| try: | |
| print "[%s] %s" % (time.ctime(), msg) | |
| finally: | |
| my_lock.release() | |
| class ThreadingTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer): | |
| pass | |
| class Socks5Server(SocketServer.StreamRequestHandler): | |
| def encrypt(self, data): | |
| return data.translate(encrypt_table) | |
| def decrypt(self, data): | |
| return data.translate(decrypt_table) | |
| def handle_tcp(self, sock, remote): | |
| try: | |
| fdset = [sock, remote] | |
| counter = 0 | |
| while True: | |
| r, w, e = select.select(fdset, [], []) | |
| if sock in r: | |
| r_data = sock.recv(4096) | |
| if counter == 1: | |
| try: | |
| lock_print( | |
| "Connecting " + r_data[5:5 + ord(r_data[4])]) | |
| except Exception: | |
| pass | |
| if counter < 2: | |
| counter += 1 | |
| if remote.send(self.encrypt(r_data)) <= 0: | |
| break | |
| if remote in r: | |
| if sock.send(self.decrypt(remote.recv(4096))) <= 0: | |
| break | |
| finally: | |
| remote.close() | |
| def handle(self): | |
| try: | |
| host = server.next() | |
| sock = self.connection | |
| remote = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| remote.connect(host) | |
| self.handle_tcp(sock, remote) | |
| except socket.error: | |
| lock_print('socket error') | |
| def main(host): | |
| print 'Starting proxy at port %d' % PORT | |
| server = ThreadingTCPServer((host, PORT), Socks5Server) | |
| server.serve_forever() | |
| if __name__ == '__main__': | |
| print 'Servers: ' | |
| for i in SERVERS: | |
| print i | |
| arg = sys.argv | |
| if len(arg) == 1: | |
| host = '' | |
| print "Use default host" | |
| else: | |
| host = arg[1] | |
| print "Use host %s" % host | |
| main(host) | 
用polipo把socks代理转换为http代理也很好用.把socks代理转换为http代理的最大好处就是可以避免dns污染,比如你使用IE并且设置ie的socks代理的话,你依然是打不开 dongtaiwang.com的;但是如果你使用IE并且设置ie的http代理的话, 这样你就可顺利打开dongtaiwang.com (建议使用polipo,privoxy有时会出错。 polipo的使用方法: http://web.archive.org/web/20130524201431/http://www.iusesoft.info/using-polipo-to-make-opera-works-with-socks5,) 不建议把此shadowsocks(它是一个socks proxy)搭配sockscap使用,因为通过ie还是打不开dongtaiwang.com related post: 
http://briteming.blogspot.com/2012/07/sockstunnel.html(利用sockstunnel翻墙) 
http://briteming.blogspot.co.uk/2012/07/proxifierssh.html
http://briteming.blogspot.co.uk/2012/06/blog-post_20.html 
------------------------
 
shadowsocks(SERVER.PY版)的改进版
 
from https://github.com/YvesChan/shadowsocks 
-------------------------
shadowsocks 原理是借助国外的 VPS 翻墙。国外的 VPS 上运行服务端,在本地运行本地端,就可以建立加密连接。 用文本编辑器编辑 config.json,请注意一定要修改密码。 server 你的 VPS 的地址 server_port 使用的服务端口 local_port 本地 socks5 端口 password 请设置一个你的密码 用winscp 上传 server.py 和 config.json 到 VPS 上的某个目录。如果是 root 用户,放到 /root/ 下;如果是其他用户,放到 /home/用户名 目录下。 用putty 登录到 VPS。 安装 python: Debian, Ubuntu: sudo apt-get install python CentOS: yum install python (其实大部分LINUX VPS已默认安装了PYTHON) cd 进入到上传的目录,运行(注意后面的 &): nohup python server.py > /dev/null & 退出 putty。接下来只要 VPS 没有重启,服务端会一直运行下去。 在本地的windows机器运行 local.exe 修改浏览器的代理设置。使用 SOCKS5 代理,地址为 127.0.0.1:刚才设置的本地socks5端口。 最简单的方法是:建一个 Chrome 的快捷方式,右键,属性,在目标的最后加上: --proxy-server=socks5://127.0.0.1:所设置的本地端口。 推荐 Firefox 配合 Autoproxy 使用,Chrome 配合 SwitchySharp 使用, 可以根据网址自动选择是否翻墙。注意使用的时候,代理协议要选择 SOCKS5 (而不是 SOCKS4 或者 HTTP)。 IE浏览器使用 SOCKS5代理,需要配合 PAC 文件, 不推荐使用。 如果哪天你翻墙失败, 那么可能是 nohup python server.py > /dev/null &所对应的python进程退出了。你可运行命令: lsof -i:所使用的服务端口号 或 netstat -anp|grep 所使用的服务端口号 查看一下有无进程在使用该端口。如果没有进程在使用该端口,说明 nohup python server.py > /dev/null &所对应的python进程退出了,需要在VPS中, 重新运行一次该命令:nohup python server.py > /dev/null & 如果你想创建账号给某人使用,可这样做: 登录VPS, nano config.json 在这一步修改server_port和password的值. 下载地址: https://cloud.github.com/downloads/clowwindy/shadowsocks-win32pack/shadowsocks.7z 以上内容适用于WINDOWS桌面系统。  
https://github.com/mengskysama/shadowsocks-rm/tree/master/shadowsocks
--------------------------
 
因为BALAN-PROXY没有加密,有时翻墙速度较慢。它不如sockstunnel的翻墙速度快。
sockstunnel: http://briteming.blogspot.com/2012/07/sockstunnel.html -----------------------------https://github.com/li-plus/secure-socks,这个翻墙项目也是没有加密的。
 |