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 from?
Of course, I could ask the user (it is a tool for programmers, so no problem with that), but it would be cooler if I just found out.
Try the following to get just the IP address via SSH:
Example:
Output:
two # in my experiment
gives the IP address.
Output:
But the results are mixed with other users and stuff. It needs more work.
You can get it in a programmatic way via an SSH library (https://code.google.com/p/sshxcute)
One thumb up for @Nikhil Katre's answer :
The one using
who
orpinky
did what is basically asked. But But But they don't give historical sessions info.Which might also be interesting if you want to know someone who has just logged in and logged out already when you start this checking.
if it is a multiuser system. I recommand add the user account you are looking for:
EDIT:
In my case, both $SSH_CLIENT and $SSH_CONNECTION do not exist.
Try the following to get just the IP address:
netstat will work (at the top something like this) tcp 0 0 10.x.xx.xx:ssh someipaddress.or.domainame:9379 ESTABLISHED