1827292 Members
3636 Online
109717 Solutions
New Discussion

Re: show IP address

 
peterchu
Super Advisor

show IP address

I have two hosts ( host A and host B ) , when a user rlogin from host A to host B , at host B side use "who" command can only show the remote host name ( host A ) but can't show the user IP address , could suggest how to know the IP address? thx
9 REPLIES 9
Mel Burslan
Honored Contributor

Re: show IP address

Normally "who" command when run without any options, do not display neither the hostname nor the IP address of the connection a user is coming from. To display the host information, command must be used with "-R" switch and this switch by default uses the function gethostbyaddr() and as long as it does not error out, it lists the name of the host next to the login information.

to obtain IP address instead of the hostname, is totally dependent on your processing of this information on the "who -R" output.

some construct like this may give you the result you are looking for:

who -R | while read id tty mon day time host
do
h=`echo $host | cut -d"(" -f2 | cut -d")" -f1`
ip=`nslookup $h | grep Address | cut -d: -f2`
echo "${id}\t${tty}\t${mon}\t${day}\t${time}\t${ip}"
done


Hope this helps


________________________________
UNIX because I majored in cryptology...
peterchu
Super Advisor

Re: show IP address

thx reply,

I can see the ip address of local user login , but can't see the remote user ( by rlogin ), could suggest how to see it ? thx
Rick Garland
Honored Contributor

Re: show IP address

The'who -um' will show who the user is, where they logged in from, what the IP address is.
If DNS resolution is in play, then you will see the host name as resolved by DNS.
Animesh Chakraborty
Honored Contributor

Re: show IP address

HostB#getip Host A
Did you take a backup?
Deepak Kulkarni
Regular Advisor

Re: show IP address

Hi Peter,

Run "who -u" command


Regards
Deepak
Devesh Pant_1
Esteemed Contributor

Re: show IP address

Peterchu,
normally I use the who -R command to get the IPs

thanks
DP
Muthukumar_5
Honored Contributor

Re: show IP address

You can get IP-Address,

remsh -l user HostB -n "who -um | awk '{ print $NF }' | xargs getip"

hth.
Easy to suggest when don't know about the problem!
prashanth_14
Occasional Advisor

Re: show IP address

$who -u
Above command should provide you required details.
Bill Hassell
Honored Contributor

Re: show IP address

Neither who nor the w command offer an IP address option. Technically, these commands only see an IP address but they try to be 'friendly' and translate the IP address into a real name. So you'll have to script a reverse loolkup by supplying the hostname and asking nslookup to return the IP.


Bill Hassell, sysadmin