How to achieve port forwarding in android

北战南征 提交于 2020-07-11 04:19:09

问题


I have created a web server in android, using NanoHttpd , I would like to forward this . If the server was running on a machine , then I can do it via ssh command like following

ssh -p 4000 -R test:80:localhost:1337 ssh.mydomain.net

I would like to do the exact same thing in android , I have explored a library called JSch , but in all example it always requires an username and password . But as you can see , in the above command , there is no username or password required .

So my question is how can achieve this using JSch , or is there any other alternatives?

Update

This is what I have tried , but I got Algorithm negotiation fail exception

    String command ="ssh -p 4000 -R test:80:localhost:8080 test.ssh.domain.net";
    public void executeSSHcommand(){
        String user = "";
        String password = "";
        String host = "test.ssh.domain.net";
        int port=4000;
        try{

            JSch jsch = new JSch();
            Session session = jsch.getSession(user, host, port);
            session.setPassword(password);
            session.setConfig("StrictHostKeyChecking", "no");
            session.setTimeout(10000);
            session.connect();
            ChannelExec channel = (ChannelExec)session.openChannel("exec");
            channel.setCommand(command);
            channel.connect();
            //channel.disconnect();
        }
      catch (JSchException e) {
            e.printStackTrace();
        }
    }

I am not sure what shall I use as user or password or even host . As you can see , in the command there no username or password is required .

Update 2

I have also tried the following

Process process = Runtime.getRuntime().exec(command)

But I get , program ssh not found , permission denied

来源:https://stackoverflow.com/questions/62672518/how-to-achieve-port-forwarding-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!