14

I can see the names of other users on the remote machine with the who command... I'd also like know the IP address of those users...

I was trying with the commands /sbin/ifconfing and netstat but I could not get positive results...

I need this solution compatible both with Linux and Unix...

Is there a command with that utility? Do I need to write a script or use a kind of pipes?

2
  • 5
    Just to be clear, who doesn't tell you about users on the same network, just users logged in to the same machine as you.
    – jw013
    Nov 10 '11 at 4:39
  • When I log in a distant machine, who gives me my origin machine name on both linux and solaris (last field, between parenthesis, when logged in locally from X I get the X display). Getting the IP from that should be easy (nslookup, host) Nov 10 '11 at 9:12
17

Try the w command, part of the procps package.

$ w
 21:12:09 up 6 days,  7:42,  1 user,  load average: 0.27, 1.08, 1.64
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
h3xx     pts/11   192.168.1.3      21:12    2.00s  0.04s  0.04s -bash
1
  • Is the procps package available in Unix (specifically Solaris)?
    – omar
    Nov 10 '11 at 19:21
5

The who manpage on my Debian Linux system shows there's an --ips option to display IPs instead of hostnames.

5
  • I'll try that option when I'll back to the Solaris network lab. In my Xubuntu system doesn't show the IP address
    – omar
    Nov 10 '11 at 0:44
  • 4
    I don't have this flag on Gentoo either; it looks like it was added by Debian in 5.96-3 as part of bug 363126 Nov 10 '11 at 1:51
  • 1
    This flag doesn't exist on my SuSe system either.
    – n0pe
    Nov 10 '11 at 3:44
  • CentOS 6.5 doesn't have that option either. Apr 29 '15 at 13:20
  • no --ips option on arch too
    – Neel Basu
    Dec 23 '18 at 20:14
1

who is the command I use, but it is not 100% reliable. The resulting names are from the PTR record for the IP address. There may or may not be a matching A record for the name.

Data from ps and netstat can be integrated if you have root privileges. Otherwise you can only make educated guesses which connection belongs to which process.

There are other tools which can be used, but I haven't found any programs that have consistent parameters and output across UNIX/Linux flavors.

1

On some old UNIX (i.e. SCO OpenServer Release 5.0.7), the w command is a good start, but the IP address is not output by default. Command arguments are sometimes required. From the man page:

-x
   Print out the hostname. This option cannot be used with
   the -u option.

-X
   Print out full hostnames. This option implies the -x
   option. Hostnames printed by the -x option are truncated
   to fit into a field; hostnames printed by the -X option
   are not truncated.

For example:

$ w
  2:39pm  up 2 days, 11:07,  1 user,  load average: 0.00, 0.00, 0.00
User     Tty       Login@   Idle   JCPU   PCPU  What
minime   ttyp0     2:31pm      -      -      -  w
$ w -x
  2:39pm  up 2 days, 11:07,  1 user,  load average: 0.00, 0.00, 0.00
User     Tty       Login@   Idle   JCPU   PCPU Hostname           What
minime   ttyp0     2:31pm      -      -      - 192.168.36.188     w -x

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.