Total Pageviews

Tuesday, 7 June 2016

利用SocksTunnel翻墙

apt-get install libevent-dev libev-dev cmake libssl-dev
(centos系统下,则为
yum install libevent-devel libev-devel cmake openssl-devel)

 git clone https://github.com/orocos-toolchain/log4cpp
cd log4cpp
mkdir build
cd build
cmake ..
make
make install
cd ~

git clone https://github.com/xxxsen/SocksTunnel/
cd SocksTunnel
mkdir build
cd build
cmake ..
(完成此步骤后,当前目录下,会出现如下东西:
CMakeCache.txt  cmake_install.cmake CMakeFiles Makefile)    
make
(完成make后,当前目录下,会出现另外2个东西:SocksTunnelLocal SocksTunnelServer 他们分别就是客户机器上的和服务器上的可执行文件)
root@AR:~/sockstunnel-cmake-version/build# ls
CMakeCache.txt cmake_install.cmake  SocksTunnelLocal
CMakeFiles Makefile     SocksTunnelServer

root@AR:~/sockstunnel-cmake-version/build# nano setting.json
(内容如下:
{
  "remote_server":"0.0.0.0",
  "remote_port":9001,
  "local_server":"127.0.0.1",
  "local_port":9000,
  "password":"yourpassword",
  "method":["chacha20"],
  "user":{
    "abcdefg":"xyzfkgw",
    "ohmyfuck":"ohyourfuck?"
  },
  "auth_timeout":30,
  "remote_proc_count":4
}  )
root@AR:~/sockstunnel-cmake-version/build# cat setting.json
{
  "remote_server":"0.0.0.0",
  "remote_port":9001,
  "local_server":"127.0.0.1",
  "local_port":9000,
  "password":"yourpassword",
  "method":["chacha20"],
  "user":{
    "abcdefg":"xyzfkgw",
    "ohmyfuck":"ohyourfuck?"
  },
  "auth_timeout":30,
  "remote_proc_count":4
}
root@AR:~/sockstunnel-cmake-version/build# ls
CMakeCache.txt cmake_install.cmake  setting.json      SocksTunnelServer
CMakeFiles Makefile     SocksTunnelLocal
root@AR:~/sockstunnel-cmake-version/build# ./SocksTunnelServer
Setting file:/root/sockstunnel-cmake-version/build/setting.json
root@AR:~/sockstunnel-cmake-version/build#
这样,服务器端就搭建好了。
注意:用户名和密码的长度是有限制的。“ 对用户名的长度限制是6-16个字符, 密码字段的长度则是6-32个字符”!!
至于password的值请尽可能的长,也是至少6个字符。

客户机器
我的是mac.
brew install libev cmake openssl
git clone https://github.com/orocos-toolchain/log4cpp
cd log4cpp
mkdir build
cd build
cmake ..
make
make install
cd ~
wget https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz
tar zxvf libevent-2.0.22-stable.tar.gz
cd libevent-2.0.22-stable
./configure
make CPPFLAGS="-I/usr/local/opt/openssl/include" LDFLAGS="-L/usr/local/opt/openssl/lib" (这样就可以make成功了。不会再遇到'openssl/bio.h' not found的提示。参见https://jira.mongodb.org/browse/CDRIVER-941 ,把CPPFLAGS="-I/usr/local/opt/openssl/include" LDFLAGS="-L/usr/local/opt/openssl/lib" 放在./configure的上方运行也行)
make install (这样libevent就编译成功了)
git clone https://github.com/xxxsen/SocksTunnel/
cd SocksTunnel
mkdir build
cd build
cmake ..
(完成此步骤后,当前目录下,会出现如下东西:
CMakeCache.txt  cmake_install.cmake CMakeFiles Makefile)
make
(完成make后,当前目录下,会出现另外2个东西:SocksTunnelLocal SocksTunnelServer 他们分别就是客户机器上的和服务器上的可执行文件)
yudeMacBook-Air:build brite$ ls
CMakeCache.txt  Makefile   SocksTunnelServer
CMakeFiles  SocksTunnelLocal  cmake_install.cmake
yudeMacBook-Air:build brite$ ./SocksTunnelLocal
dyld: Library not loaded: liblog4cpp.6.0.dylib
Referenced from: /Users/brite/sockstunnel-cmake-version/build/./SocksTunnelLocal
  Reason: image not found
Trace/BPT trap: 5
yudeMacBook-Air:build brite$ sudo find / -name liblog4cpp.6.0.dylib
Password:
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory
/Users/brite/sockstunnel-cmake-version/log4cpp/build/liblog4cpp.6.0.dylib
/usr/local/lib/liblog4cpp.6.0.dylib
yudeMacBook-Air:build brite$ export DYLD_LIBRARY_PATH=/usr/local/lib/
yudeMacBook-Air:build brite$ sudo echo "export DYLD_LIBRARY_PATH=/usr/local/lib/" >> /etc/profile
yudeMacBook-Air:build brite$ . /etc/profile
yudeMacBook-Air:build brite$ ./SocksTunnelLocal
Setting file:/Users/brite/sockstunnel-cmake-version/build/setting.json
yudeMacBook-Air:build brite$ nano setting.json
(内容如下:
{
  "remote_server":"你的服务器的公网ip",
  "remote_port":9001,
  "local_server":"127.0.0.1",
  "local_port":9000,
  "password":"yourpassword",
  "method":["chacha20"],
  "current_user":"ohmyfuck",
  "current_pwd":"ohyourfuck?",
  "local_proc_count":4
}  )
yudeMacBook-Air:build brite$ ./SocksTunnelLocal

这样,客户端就搭建好了。
设置本地机器的浏览器的socks5代理为127.0.0.1:9000,即可翻墙。

如果你的本地机器为windows,则到此地址https://github.com/xxxsen/SocksTunnel/tree/master/release/Windows下载里面所有的exe文件和dll文件到你的windows机器的某个目录,比如e:\SocksTunnel-client\里面。然后复制c:\windows\system32\cmd.exe到e:\SocksTunnel-client\里面,运行cmd.exe,接着在cmd.exe里面输入SocksTunnelLocal.exe ,回车,windows机器下的客户端就运行起来了。当然你需要先创建setting.json文件,
文件的内容如下:
{
  "remote_server":"你的服务器的公网ip",
  "remote_port":9001,
  "local_server":"127.0.0.1",
  "local_port":9000,
  "password":"yourpassword",
  "method":["chacha20"],
  "current_user":"ohmyfuck",
  "current_pwd":"ohyourfuck?",
  "local_proc_count":4
}
接着在cmd.exe里面输入SocksTunnelLocal.exe ,回车,windows机器下的客户端就运行起来了,然后设置本地机器的浏览器的socks5代理为127.0.0.1:9000,即可翻墙。


项目地址:https://github.com/xxxsen/SocksTunnel
(http://libevent.org/)