获取 ConnectException:无法连接到 192.168.2.100(端口 22)ECONNREFUSED Android 和 JSCH

Getting ConnectException: failed to connect to 192.168.2.100 (port 22) ECONNREFUSED with Android and JSCH

我收到 java.net.ConnectException:无法连接到 192.168.2.100(端口 22):连接失败:ECONNREFUSED(连接被拒绝)当通过 SSH 连接到服务器时 JSCH-0.1.54 Android.

防火墙配置为允许 IP 地址通过。 从 Windows 到服务器的 SSH 连接可以通过 Putty 实现。 服务器的IP地址没问题

还能是什么?

我使用的代码如下:

protected Long doInBackground(String... params)
{
    try
    {
        System.setProperty("http.keepAlive", "false");
        JSch jsch = new JSch();
        Session session = jsch.getSession("root", "192.168.2.100", 22);
        session.setPassword("Password");
        session.setTimeout(10000);
        Properties props = new Properties();
        props.put("StrictHostKeyChecking", "no");
        session.setConfig(props);
        session.connect();
        ChannelExec channel = (ChannelExec) session.openChannel("exec");
        if(params[0]=="poweroff")
        {
            LogPublic("Server wird heruntergefahren");
        }
        else if(params[0]=="reboot")
        {
            LogPublic("Server wird neugestartet");
        }
        channel.setCommand(params[0]);
        channel.connect();
        channel.disconnect();
        session.disconnect();
        jsch.removeAllIdentity();
        jsch = null;
        return new Long(1);
    }
    catch (Exception ex)
    {
        LogPublic(ex.getMessage());
        return new Long(0);
    }
}

解决方案是将服务器的静态 IP 地址设置在路由器的 DHCP 范围之外,因为这会导致 IP 冲突。