美文网首页
拓展sshxcute使之支持SOCKS5代理

拓展sshxcute使之支持SOCKS5代理

作者: 尤育最 | 来源:发表于2018-08-07 17:24 被阅读0次

sshxcute是对JSCH的封装,通过使用这个框架我们能很快的上手远程操作ssh。但是这个设计之初没有实现对proxy socks5的支持,通过修改源码使之支持。

public class ConnBean {
 private ProxyCredential proxyCredential;
 ......
 public static class ProxyCredential {
        private String host;
        private int port;
        private String username;
        private String password;

        public ProxyCredential() {
            this(null, 0, null, null);
        }

        public ProxyCredential(String host, int port, String username, String password) {
            this.host = host;
            this.port = port;
            this.username = username;
            this.password = password;
        }

        public String getHost() {
            return host;
        }

        public void setHost(String host) {
            this.host = host;
        }

        public int getPort() {
            return port;
        }

        public void setPort(int port) {
            this.port = port;
        }

        public String getUsername() {
            return username;
        }

        public void setUsername(String username) {
            this.username = username;
        }

        public String getPassword() {
            return password;
        }

        public void setPassword(String password) {
            this.password = password;
        }
    }
}
  • 修改SSHExec.class,添加代理实现
public Boolean connect() {
 ......
 if (this.conn.getProxyCredential() != null) {
     session.setProxy(getProxy());
 }
 .......
}
private ProxySOCKS5 getProxy() {
    String proxyHost = this.conn.getProxyCredential().getHost().trim();
    int proxyPort = this.conn.getProxyCredential().getPort();
    String proxyUsername = this.conn.getProxyCredential().getUsername().trim();
    String proxyPassword = this.conn.getProxyCredential().getPassword().trim();
    ProxySOCKS5 proxy = new ProxySOCKS5(proxyHost, proxyPort);
    proxy.setUserPasswd(proxyUsername, proxyPassword);
    return proxy;
}
  • 然后在初始化的时候时候ConnBean的时候添加代理的就可以了。

当然如果没有不是梨花

ConnBean.ProxyCredential proxyCredential = new ConnBean.ProxyCredential();
proxyCredential.setHost("host");
proxyCredential.setPort(port);
proxyCredential.setUsername("username");
proxyCredential.setPassword("password");
String host = "serverHost";
String username = "serverUsername";
String password = "serverPassword";
ConnBean cb = new ConnBean(host, username, password);
cb.setProxyCredential(proxyCredential); #如果不需要代理就直接不调用这行就可以了。
SSHExec ssh = SSHExec.getInstance(cb);

相关文章

  • 拓展sshxcute使之支持SOCKS5代理

    sshxcute是对JSCH的封装,通过使用这个框架我们能很快的上手远程操作ssh。但是这个设计之初没有实现对pr...

  • 拓展sshxcute使之支持切换用户执行多条命令

    实际工作场景中有时候会遇到需要切换其他用户来执行多条linux命令,但是测试发现无论是通过 ";","&&","|...

  • Android Studio Gradle read time

    ⚠️:此方法需要代理(或者可以试试使用阿里云的依赖项) 设置代理 ⚠️:使用过 Socks5 代理但是依旧超时,使...

  • Socks5 udp代理

    socks5在socks4上多了对udp代理的支持,可以说是“全能代理”了。udp代理较对比tcp代理,流程上要复...

  • Go 使用代理方法

    链接远程服务器,设置SSH端口转发 将SOCK5代理转发为HTTP代理(Go不支持SOCKS5代理) 设置http...

  • Git代理设置

    设置代理 或者 设置socks5代理 删除代理 或者

  • Android Studio Gradle无法获取pom文件

    shadowsocks socks5 gradle 全局代理:

  • 代理IP的选择

    站大爷代理IP种类有5种,分别是短效优质代理、短效socks5代理、一手私密代理、一手socks5代理和独享IP池...

  • socks4和socks5的区别

    SOCKS代理又分为SOCKS4和SOCKS5 二者不同的是SOCKS4代理只支持TCP协议(即传输控制协议),而...

  • Polipo全局代理设置方法

    Shadowsocks是我们常用的代理工具,它使用socks5协议,而终端很多工具目前只支持http和https等...

网友评论

      本文标题:拓展sshxcute使之支持SOCKS5代理

      本文链接:https://www.haomeiwen.com/subject/srpavftx.html