1833860 Members
2222 Online
110063 Solutions
New Discussion

GETTING IPADDRESS

 
SOLVED
Go to solution
Hemant_2
Occasional Contributor

GETTING IPADDRESS

Hi,
When I do "who am I -R "the output gives me my terminal no. and the hostname (if defined in /etc/hosts) or ipaddress if not defined in /etc/hosts file.
Are there any other ways by which I can get the ipaddress for the connection ?

Regards
Hemant
11 REPLIES 11
Deepak Extross
Honored Contributor

Re: GETTING IPADDRESS

"who -T" will give you the IP addresses of all users logged in.
You can grep for your login name / tty from this list, if you want.

HTH

Frederic Sevestre
Honored Contributor

Re: GETTING IPADDRESS

Hi,
you can try :
who -u | grep $(who am i| awk '{ print $2 }')

Fr??d??ric
Crime doesn't pay...does that mean that my job is a crime ?
James Beamish-White
Trusted Contributor

Re: GETTING IPADDRESS

Since this is -probably- related to setting the display, you can get just the IP address from:

who am i -u | awk '{print $8}'

Party on Dude!
James
GARDENOFEDEN> create light
G. Vrijhoeven
Honored Contributor

Re: GETTING IPADDRESS

Hi,

Do a who -R and and filter out the hostname. with nslookup you should be able to get te ip-adress.

Gideon
Hemant_2
Occasional Contributor

Re: GETTING IPADDRESS

Hi All,
Thanks for you very fast replies but I want to get ipaddress without using "who" or /etc/hosts for a session.
The situation is like this,
In /etc/hosts file 2 different ip address have same hostname but who am i will always show me this common "hostname" so I need to avoid using "who" and /etc/hosts file.
So based on say terminal name which will be different for both.
That is what I meant.


Hemant
G. Vrijhoeven
Honored Contributor

Re: GETTING IPADDRESS

Hi,

try netstat -an

Gideon
Steven Gillard_2
Honored Contributor
Solution

Re: GETTING IPADDRESS

I wrote the following C program to get around a similar problem - I didn't want to reverse lookup the IP address but there's no way to tell 'who' not to do this.

This program emulates a 'who -u' by reading the utmpx file and displaying a list of users currently logged in, but prints the IP address as stored in the utmpx entry instead of resolving the hostname.

Compile as follows (you'll need gcc or the ANSI C compiler)

$ cc -Ae mywho.c -o mywho

Have fun...
Carlos Fernandez Riera
Honored Contributor

Re: GETTING IPADDRESS

See man last:

i.e:

last -20 -R pts/ty
unsupported
Krishna Prasad
Trusted Contributor

Re: GETTING IPADDRESS

Try

ip=`env | grep TERM`
nslookup $ip
Positive Results requires Positive Thinking
Fred Martin_1
Valued Contributor

Re: GETTING IPADDRESS

Would getip command be useful here?

getip hostname

returns the IP address of the host.
fmartin@applicatorssales.com
Hemant_2
Occasional Contributor

Re: GETTING IPADDRESS

Hi ,
Steven Gillard has provided the a very nice C program and these has solved my problem.
Thanks very much Steven !

And also thanks to all who spend there time giving me a solution.

And also THANKS to HP forum.

Regards
Hemant