Total Pageviews

Tuesday 21 June 2016

利用基于ruby的socks-tunnel-demo翻墙

登陆你的linux vps,编译ruby.
然后,
git clone https://github.com/cctiger36/socks-tunnel-demo socks-tunnel-demo-by-cctiger36
cd socks-tunnel-demo-by-cctiger36


root@VM:~/socks-tunnel-demo-by-cctiger36# ls
Gemfile README.md coder.rb local.rb

Gemfile.lock buffer.rb config.rb remote.rb
root@VM:~/socks-tunnel-demo-by-cctiger36# nano config.rb
root@VM:~/socks-tunnel-demo-by-cctiger36# cat config.rb
Config = {
  local_server_host:  "127.0.0.1",
  local_server_port:  "8079",
  remote_server_host: "0.0.0.0",
  remote_server_port: "你指定的端口号",
  delimiter:          "DRECOMADVENTCALENDER",
  cipher:             "AES-256-CBC",
  salt:               "V\x11\x97\xA6r\xEF[\xFE",
  password:           "你指定的密码",
}
root@VM:~/socks-tunnel-demo-by-cctiger36# ruby remote.rb
(要在后台运行的话,则nohup ruby remote.rb > /dev/null &)
这样服务器端就搭建好了。
注意:服务器上的配置文件config.rb里指定的local_server_port的值8079其实不重要,不必修改它。也就是说客户机器上的配置文件config.rb里的local_server_port的值其实是可以随意设置的只要不设为客户机器上的已占用的端口即可。比如设为8081,不一定要设为服务器上的配置文件config.rb里指定的local_server_port的值。

在客户机器上。
在linux桌面系统上,编译ruby.
(在mac上,运行brew install ruby)
然后,
git clone https://github.com/cctiger36/socks-tunnel-demo socks-tunnel-demo-by-cctiger36
cd socks-tunnel-demo-by-cctiger36
nano config.rb
(config.rb的内容:
Config = {
  local_server_host:  "127.0.0.1",
  local_server_port:  "8081",
  remote_server_host: "你的vps的ip",
  remote_server_port: "你指定的端口号",
  delimiter:          "DRECOMADVENTCALENDER",
  cipher:             "AES-256-CBC",
  salt:               "V\x11\x97\xA6r\xEF[\xFE",
  password:           "你指定的密码",

}  )
ruby local.rb
(显示Start socks5 at 127.0.0.1:8081)
要在后台运行的话,则nohup ruby local.rb > /dev/null &
这样客户端就搭建好了。

注意:本地机器上的ruby必须为2.2.x版。我的mac系统为最新的10.11,运行brew install ruby后,所安装的ruby是2.2.x版:
yudeMacBook-Air:socks-tunnel-demo brite$ ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin15]
yudeMacBook-Air:socks-tunnel-demo brite$
服务器上的ruby的版本不要求一定要为2.2.x版。事实上,我的服务器上的ruby的版本为2.0.x版。

然后设置浏览器的socks5代理为127.0.0.1:8081,即可翻墙。

项目地址:https://github.com/cctiger36/socks-tunnel-demo

注意:如果运行了nohup ruby remote.rb > /dev/null & ,没过多久,服务器端就退出了,那么请参考此文http://briteming.blogspot.com/2016/08/daemonize-daemon.html的后半部,用daemonize来运行ruby remote.rb ,这样,服务器端就不会再轻易退出。

相关帖子:https://briteming.blogspot.com/2016/09/sockstunnel.html