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.

I am using ssh to access another machine and require the IP from which I am sshing from. Finger gives this, but I don't know how to isolate this from the information given. So far I have:

finger | grep $USER

Which produces:

jonno     Jonathan Mackenzie   pts/9          Sep 21 16:23 (111.111.111.111)

What is the last grep required to isolate the IP address (i changed it here for security reasons)?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

Quick and dirty:

finger | grep $USER | egrep -o "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
share|improve this answer
add comment

When you ssh somewhere a few environment variables are set:

SSH_CLIENT 
SSH_TTY  
SSH_CONNECTION

do take a look at them, they are quite useful.

share|improve this answer
add comment

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.