Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

If computer A SSHs computer B, can computer B find the IP of computer A? If so, how?

share|improve this question
    
Handy when using C9.io or other services to get to EC2, and then re-restricting the network traffic rules to that IP. –  Danny Staple Dec 20 '13 at 15:01

5 Answers 5

up vote 4 down vote accepted

SSH connection info is also stored in the SSH_CONNECTION environmental variable.

You should be able to view this by entering echo $SSH_CONNECTION.

share|improve this answer

this is what you want, in a terminal:

lsof -i :ssh

it gives you the names (if available of computers sshin into your computer), if you speficically want their IP address, maybe you want to ping the name to see the IP or do an nslookup or go to http://ip2location.com ....

share|improve this answer

For SSH on a specific interface, you can also use

tcpdump -i interface port 22

This will work for linux and mac and if you have a tcpdump port for windows, it will work the same way.

share|improve this answer

Yes. Just run netstat:

netstat --tcp --numeric

Look for the IP using the port 22. --numeric forces netstat to show IPs and --tcp only shows TCP connections

share|improve this answer
    
Oh and how do I do that on a Mac? –  JShoe Jul 30 '11 at 3:16
1  
According to the manpage here: developer.apple.com/library/mac/#documentation/Darwin/Reference/… you should type netstat -n. There is no tcp filtering. –  nmat Jul 30 '11 at 3:24

Yes, and here is how in Windows:

The netstat -a command shows all conections as they happen.

enter image description here

I am not a Linux guru, but it is very similar, and the actual base command is the same, I believe:

http://www.thegeekstuff.com/2010/03/netstat-command-examples/

share|improve this answer
    
For the record you would be looking for an IP address with :22 at the end. –  KCotreau Jul 30 '11 at 3:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.