0

Hello I want to write a program that connects a phone to a router through the Ssh protocol and use jsch library.

But this error shows when connecting.

05-06 05:53:58.754 3985-4006/com.example.amir133.tel W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xe3031c00, error=EGL_SUCCESS
05-06 05:54:08.692 3985-4046/com.example.amir133.tel W/System.err: com.jcraft.jsch.JSchException: timeout: socket is not established
    at com.jcraft.jsch.Util.createSocket(Util.java:394)
    at com.jcraft.jsch.Session.connect(Session.java:215)
    at com.jcraft.jsch.Session.connect(Session.java:183)
    at com.example.amir133.tel.SSHManager.execute(SSHManager.java:89)
    at com.example.amir133.tel.MainActivity$1$1.doInBackground(MainActivity.java:52)
    at com.example.amir133.tel.MainActivity$1$1.doInBackground(MainActivity.java:47)
    at android.os.AsyncTask$2.call(AsyncTask.java:288)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    at java.lang.Thread.run(Thread.java:818)

I checked the same questions as this and this, but none of them solved my problem.

I added to the manifist Internet access.

Through the putty, I can connect to this router so there is no problem on the router.

Can someone help ?

MainClass :

connect.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            new AsyncTask<Integer, Void, Void>(){
                @Override
                protected Void doInBackground(Integer... params) {
                    try {
                        SSHManager ssh=new SSHManager("amir","123","192.168.66.120");
                        ssh.execute();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return null;
                }
            }.execute(1);

        }
    });

SSHManager Class :

public class SSHManager {
    private JSch jsch;
    private String hostname = null;
    private String username;
    private String password;
    private Session session;
    private ChannelExec channel;
    private int connectioPort = 22;
    private void SSHManager (String userName,
                                            String password, String connectionIP) {
        this.username = userName;
        this.password = password;
        this.hostname = connectionIP;
    }
    public String execute() {

        try {
            jsch = new JSch();
            session = jsch.getSession(username, hostname, 22);
            session.setPassword(password);
            session.setConfig("StrictHostKeyChecking", "no");
            session.setTimeout(10000);
            session.connect();
            channel = (ChannelExec) session.openChannel("exec");
            channel.setCommand("en\n123\nconf t\nexit");
            channel.connect();
            channel.disconnect();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;

    }
}
Community
  • 1
  • 1
Amir133
  • 2,372
  • 2
  • 18
  • 34

0 Answers0