Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

what address I am logged through?

Status
Not open for further replies.

ogniemi

Technical User
Nov 7, 2003
1,041
PL
In the system there are 2 network ents configured (both can be used for remote access).

The will be executed script which will swap a desired IP address with a new one - I need to avoid terminal loss in case user logged to the system via the address which will be swapped by a new one.

has anyone idea how to perform such test?

I openssh session I can obtain the address with command:

$ env|grep ^SSH_CONNECTION|awk '{print $(NF-1)}'
10.122.22.16

But when I switch (su) root account (I need to switch with "su -" gettign root's env) the information is lost:

# env|grep ^SSH_CONNECTION|awk '{print $(NF-1)}'
#


Maybe someone knows some more reliable method for getting the address?
 
You can run a netstat command.

netstat -an | grep YourOriginatingIP

This should show you output similar to...
tcp4 0 0 aaa.aaa.aaa.aaa.22 xxx.xxx.xxx.xxx.yyyy ESTABLISHED

The aaa.aaa.aaa.aaa above would be the address you are connected through.

You can get the originating IP with this code....
ORIGIP=$(who am i | awk '{print $6}' | sed 's/(//' | sed 's/)//')

Jim Hirschauer
 
Hi Ogniemi,

As long as its a logged in session (using a tty) you could use something like the following.

Code:
mytty=`tty | sed 's^/dev/^^'`
who | grep " $mytty " | awk '{print $NF}' | tr -d '()'

Brgds.

____________________
Sometimes it pays to stay in bed on Monday, rather than spending the rest of the week debuging Mondays code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top