Find the IP address of the client in an SSH session

后端 未结 19 1031
刺人心
刺人心 2020-12-12 10:48

I have a script that is to be run by a person that logs in to the server with SSH.

Is there a way to find out automatically what IP address the user is connecting fr

19条回答
  •  旧巷少年郎
    2020-12-12 11:34

    You can get it in a programmatic way via an SSH library (https://code.google.com/p/sshxcute)

    public static String getIpAddress() throws TaskExecFailException{
        ConnBean cb = new ConnBean(host, username, password);
        SSHExec ssh = SSHExec.getInstance(cb);
        ssh.connect();
        CustomTask sampleTask = new ExecCommand("echo \"${SSH_CLIENT%% *}\"");
        String Result = ssh.exec(sampleTask).sysout;
        ssh.disconnect();   
        return Result;
    }
    

提交回复
热议问题