有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Android中的java 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) 个答案

  1. # 1 楼答案

    考虑使用{a1}库

    JSch is a pure Java implementation of SSH2.

    this example显示以下各项的用法:

    session.setPortForwardingR(rport, lhost, lport);