Android中的SSH反向隧道

时间:2014-01-18 05:11:35

标签: java android ssh

我正在使用SSHJ库建立反向ssh隧道,但没有运气..

Error: Unable to resolve host name

使用的代码:

final SSHClient ssh = new SSHClient(new AndroidConfig());
Command cmd = null;
// Adds a nullHostKeyVerifier
ssh.addHostKeyVerifier(new NullHostKeyVerifier());
// default port number
int pn = 22;
// connect to the machine
try {
    String pemkey = "/mnt/sdcard/lamp.pem";
    ssh.loadKeys(pemkey);
    ssh.connect("-R 8080:localhost:8080 root@54.X.X.X ",pn);
    // Authenticate with the password entered
    // start a new session
    final Session session = ssh.startSession();
} catch (IOException e) {
    Log.e("message", e.getMessage(), e);
}

1 个答案:

答案 0 :(得分:1)

考虑使用JSch

  

JSch是SSH2的纯Java实现。

this example显示使用:

session.setPortForwardingR(rport, lhost, lport);