Total Pageviews

Tuesday, 3 November 2015

利用基于java的翻墙工具:lightsocks-java翻墙

A fast proxy that helps you bypass firewalls.

System requirements

  • Jdk 7+ 
  • maven

How to build

On Server

mvn package -Pserver

On Client 

mvn package -Pclient
this tool is implemented by netty , you can get more information from netty.io,there is also a maven plugin maven-shade-plugin for packaging the dependency into one jar .

How to use

Both the server and client tool will look for config.properties in the current directory or classpath. You can use -c option to specify another configuration file. Download the sample config.properties, change the following values as you wish:
server.ip             server ip or hostname
server.port          server port
password            password used to encrypt data
method               default aes-cfb-128
local.ip                local address
local.port             local socks5 proxy port
On Server
java -jar lightsocks-server.jar -c=config.propeties

On Client
java -jar lightsocks-client.jar -c=config.propeties

Change proxy settings of your browser to
SOCKS5 127.0.0.1:8888

Reference

from https://github.com/lightsocks/lightsocks-java
------------

我的搭建方法:

服务器端-
首先搭建jdk环境:
wget https://download.oracle.com/java/18/latest/jdk-18_linux-x64_bin.tar.gz  
(这是直链地址
tar xvf jdk-18_linux-x64_bin.tar.gz 
...
(apt-get install -y default-jdk或者openjdk-8-jdk 
centos系统下,则yum install -y java-1.8.0-openjdk
不再推荐使用包管理器安装jdk环境
这样jdk环境就搭建好了。

接着是搭建maven环境:

安装Maven

建议这样安装Maven:
apt-get install -y maven*
(yum install -y maven*)

而不要去下载apache-maven-3.1.1-bin.tar.gz文件:http://apache.mirror.anlx.net/maven/maven-3/3.1.1/binaries/apache-maven-3.1.1-bin.tar.gz


否则运行mvn package时,可能遇到类似这样的错误:
https://github.com/loveinsky100/panama/issues/7


root@AR:~# mvn -version
Apache Maven 3.0.5 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 11:22:22-0400)


Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-042stab103.6", arch: "amd64", family: "unix"
root@AR:~#
(运行 mvn -version 命令检验是否正确地安装了 Maven。如上的显示则表明正确地安装了 Maven。)

然后,
git clone https://github.com/lightsocks/lightsocks-java
cd lightsocks-java
root@AR:~/lightsocks-java# mvn package -Pserver
(此时,lightsocks-java目录里面,会生成target目录,target目录里面会有一个lightsocks-server.jar文件)
root@AR:~/lightsocks-java# cd target
root@AR:~/lightsocks-java/target# nano config.properties
(内容如下:
server.ip=0.0.0.0
server.port=8889
password=你自设的密码
method=aes-cfb-128
 )
root@AR:~/lightsocks-java/target# java -jar lightsocks-server.jar -c=config.properties 
(不过这条命令是运行在前台的,容易退出,我们可利用systemd来让该命令运行为service:
nano /etc/systemd/system/lightsocks-java.service
其内容为:
[Unit]
After=network.target

[Service]
ExecStart=/usr/bin/java -jar /root/lightsocks-java/target/lightsocks-server.jar -c=/root/lightsocks-java/target/config.properties
Restart=always

[Install]

WantedBy=multi-user.target

然后运行:
systemctl start lightsocks-java
systemctl enable lightsocks-java

这样,lightsocks-java的服务器端就搭建好了.)

在客户端机器上.
如果你的客户端机器为linux桌面系统,则如上安装java环境和maven环境。
如果你的客户机器为mac,则访问:
https://download.oracle.com/java/18/latest/jdk-18_macos-x64_bin.tar.gz
 (这是直链地址
下载这个tar.gz文件,解压,设置解压出来的目录里的可执行文件java的环境变量。
这样mac上的jdk18环境就搭建好了

参考:
https://www.oracle.com/java/technologies/downloads/#jdk18-linux 
https://www.oracle.com/java/technologies/downloads/#jdk18-mac 
https://github.com/pubyun/macdev/blob/master/java.md
http://han.guokai.blog.163.com/blog/static/136718271201301183938165/
git clone https://github.com/lightsocks/lightsocks-java
cd lightsocks-java
mvn package -Pclient
(此时,lightsocks-java目录里面,会生成target目录,target目录里面会有一个lightsocks-client.jar文件)
nano config.properties
(内容为:
server.ip=your_vps_ip
server.port=8889
password=你自设的密码
method=aes-cfb-128
local.ip=127.0.0.1
local.port=1085 )

运行:
java -jar ./target/lightsocks-client.jar -c=config.properties 
(这样,lightsocks-java的客户端就搭建好了)
然后,设置浏览器的socks5代理为127.0.0.1:1085,即可翻墙。
翻墙速度还不错,看youtube,很流畅。
注:如果第一次翻墙失败,多刷新几次浏览器即可