【Linux服务】socket5代理服务器搭建

如果在系统中需要搭建socket代理服务,可以参照如下脚本:

1、将账号密码替换成自己想要的设置

2、将"端口"替换成需要的端口号

3、运行脚本,即可完成安装

4、可通过netstat -lntp | grep ss5命令查看端口是否正常监听

5、通过脚本 curl myip.ipip.net --socks5 ip:port -U user:password验证带来是否安装完成

#/bin/bash
yum -y install gcc openldap-devel pam-devel openssl-devel
mkdir -p /data/ss5
cd /data/ss5
wget https://nchc.dl.sourceforge.net/project/ss5/ss5/3.8.9-8/ss5-3.8.9-8.tar.gz
tar -xf ss5-3.8.9-8.tar.gz
cd ss5-3.8.9/
./configure
make
make install 
echo 'auth    0.0.0.0/0               -               u
permit -	0.0.0.0/0	-	0.0.0.0/0	-	-	-	-	-	'  >  /etc/opt/ss5/ss5.conf
echo '账号 密码' > /etc/opt/ss5/ss5.passwd
echo 'SS5_OPTS=" -u root -b 0.0.0.0:端口"' >  /etc/sysconfig/ss5
chmod u+x /etc/rc.d/init.d/ss5
chkconfig --add ss5
chkconfig ss5 on
service ss5 start

如果有需要的java使用代理也可参照如下代码:


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sun.net.SocksProxy;
import java.io.IOException;
import java.net.*;
import java.util.concurrent.Callable;

/**
 * @description:
 * @author: syy
 * @create: 2020-05-14 16:56
 **/

public class SocketCheckThread implements Callable
{
    private Logger logger = LoggerFactory.getLogger(SocketCheckThread.class);

    /**
     * 等待超时时间
     */
    private final int SEC_WAIT = 5;

    private String ip;

    public SocketCheckThread(String ip)
    {
        this.ip = ip;
    }


    @Override
    public CheckStatus call()
    {
        CheckStatus checkStatus = new CheckStatus();
        checkStatus.setIp(ip);
        checkStatus.setStatus(check());
        return checkStatus;
    }


    private boolean check()
    {
        Socket socket = null;
        try {

            Proxy proxy = createProxy();
            socket = new Socket(proxy);
            socket.connect(new InetSocketAddress(this.ip ,80), SEC_WAIT * 1000);
            return true;
        }
        catch (Exception e) {
            logger.debug("检测超时{}",this.ip,e);
        }
        finally
        {
            try
            {
                socket.close();
            }
            catch (IOException e)
            {
                logger.debug("关闭socket失败",e.getMessage());
            }
        }
        return false;
    }


    private static Proxy createProxy() {
        // 设置认证
        String proxyAddr = ip;
        int proxyPort = port;
        Authenticator.setDefault(new Authenticator(){
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("user", "password".toCharArray());
            }
        });

        SocksProxy proxy = SocksProxy.create(new InetSocketAddress(proxyAddr, proxyPort),5);
        return proxy;
    }

}

 

你可能感兴趣的:(服务器)