Capture IP Adress

hello

I need for a script to capture the ip address from the connected user.
I have 5 logical partitions.
With "who", i have the ip adress, but only for 2 servers.
Do you know another command to know the ip address of connected clients ?

thank you

See if 'netstat -a|grep ESTABLISHED' gives you what you want.

thank you, but i need to capture the IP of the last login.
To explain, i try to automatically launch a program when a user connect (with .profile), and this program need the IP adress.
thank you

How about in your .profile you capture the IP with:

 last $LOGNAME -1|awk '{print $3}'

This will give you the IP address or hostname if their IP is in dns or the local hosts file.

Good luck

hello

Thank you for your response
But When i write it, I have the result :

root pts/2 Jan 26 09:06 still logged in
root pts/2 Jan 26 09:06 - 09:06 (00:00)

and no IP :frowning: that's my problem, the ip for who, last, etc... isnot given.
For precision, i use ssh.
It is a p570 with 6 virtual partitions. Only this partition has this problem (all use ssh )

thank you

i have this on a rs6k which sets the DISPLAY everytime a user log in

  tty | sed -e 's|/dev/||' | read tty
  who | grep "$tty" | sed -e 's/.*(//' -e 's/).*//' | read ip
  export DISPLAY="$ip:${1-0.0}"
  echo "DISPLAY=$DISPLAY"

thank you but sorry, i have nothing for result :frowning:

Give us the output of:

tty


who

who am i

who /etc/utmp

And paste it here.

Is there a problem with the /etc/utmp file on this node?

good morning

Here the result of these commands :

/# tty
/dev/pts/0
/# who
root pts/0 Jan 27 09:32
/# who /etc/utmp | pg
root pts/0 Jan 27 09:32
/# who am i
root pts/0 Jan 27 09:32

thank you

I'm going to strike out on that one. I'm curious why your /etc/utmp isn't reporting the IP address. Perhaps you could delete the /etc/utmp (move it to another name rather) and let it create a new one.

Does the 'last' command report an IP address? Try:

who /var/adm/wtmp|head

hello !

Thank you very much for your help

Here the result of this command:

who /var/adm/wtmp|head

root pts/0 Jun 23 12:44 (ADMIN)
root vty0 Jun 23 12:48
root vty0 Jun 23 15:38
root ftp266 Jun 23 16:18 (ADMIN)
root vty0 Jun 23 16:59
root vty0 Jun 23 17:16
root vty0 Jul 11 16:47
root vty0 Jul 11 16:54
root pts/0 Jul 12 16:59
root pts/0 Jul 13 09:59

thank you

I can't find any other way to determine the connecting IP address. I would now try to figure out why the who command isn't reporting the ip address -- that is the root of the problem.

Try making a new post about that.

sorry

Do you have lsof? Code in .profile can trace back from the current shell to the instance of the program that provides the socket i/o (telnetd, sshd, etc) and use lsof to get the remote ip.

hello

I don't know isof, but i'm looking for with google :wink:
thank you for your help.

Not isof, it's lsof. (LiSt Open Files)