我如何知道在同一台远程计算机上登录的其他用户的IP地址?


13

我可以使用以下who命令查看远程计算机上其他用户的名称... 我也想知道这些用户的IP地址...

我正在尝试使用命令/sbin/ifconfingnetstat但无法获得积极的结果...

我需要与Linux和Unix都兼容的解决方案...

该实用程序有命令吗?我需要编写脚本还是使用某种管道?


5
请注意,who不会告诉您有关同一网络上的用户的信息,只是告诉您与您登录到同一台计算机上的用户有关的信息。
jw013

当我登录一台远程计算机时,请who在linux和solaris上给我我的源计算机名称(括号中的最后一个字段,当从XI本地登录时将显示X)。从获取IP应该很容易(nslookuphost
AProgrammer

Answers:


17

尝试使用w命令,它是procps软件包的一部分。

$ 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

procps软件包在Unix(特别是Solaris)中可用吗?
omar

5

who我的Debian Linux系统上的手册页显示有一个--ips显示IP而不是主机名的选项。


当我回到Solaris网络实验室时,将尝试该选项。在我的Xubuntu系统中未显示IP地址
omar

4
我在Gentoo上也没有此标志;它似乎是Debian在5.96-3中添加的,它是bug 363126的
Michael Mrozek

1
此标记在我的SuSe系统上也不存在。
2011年

CentOS 6.5也没有该选项。
汇总

--ips拱门上也没有选择
Neel Basu

1

who是我使用的命令,但并非100%可靠。结果名称来自IP地址的PTR记录。该名称可能匹配也可能不匹配。

从数据psnetstat可以,如果你有root权限进行整合。否则,您只能做出有根据的猜测,即哪个连接属于哪个进程。

还有其他可以使用的工具,但是我还没有找到具有一致参数和跨UNIX / Linux风格输出的程序。


1

在某些旧的UNIX(即SCO OpenServer版本5.0.7)上,该w命令是一个很好的开始,但是默认情况下不会输出IP地址。有时需要命令参数。从man页面:

-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.

例如:

$ 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
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.