哪些进程正在使用UNIX上的哪些端口?
时间:2020-03-06 14:38:56 来源:igfitidea点击:
我需要找出Unix计算机(HP Itanium)上哪些进程连接了哪些端口。不幸的是,没有安装lsof
,我无法安装它。
有谁知道替代方法?一段相当长的Google搜寻会话并没有发现任何问题。
解决方案
netstat -l(假设它随该版本的UNIX一起提供)
尝试使用" pfiles PID"来显示一个进程的所有打开文件。
给定(几乎)Unix上的所有内容都是一个文件,而lsof会列出打开的文件...
Linux:netstat -putan或者lsof | grep TCP
OSX:lsof | grep TCP
其他Unixen:lsof
方法...
netstat -pln
编辑:仅Linux,在其他UNIX上,netstat可能不支持所有这些选项。
netstat -ln | awk '/^(tcp|udp)/ { split(, a, /:/); print , a[2]}' | sort -u
为我们提供活动的tcp / udp端口。然后,我们可以使用以fuser -n tcp
或者fuser -n udp
作为根目录的端口,并假设fuser
是GNU热熔器或者具有类似的选项。
如果我们需要更多帮助,请告诉我。
假设这是HP-UX?我们安装的Ptools呢?如果是这样,则可以使用" pfiles"查找应用程序正在使用的端口:
pfiles prints information about all open file descriptors of a process. If file descriptor corresponds to a file, then pfiles prints the fstat(2) and fcntl(2) information. If the file descriptor corresponds to a socket, then pfiles prints socket related info, such as the socket type, socket family, and protocol family. In the case of AF_INET and AF_INET6 family of sockets, information about the peer host is also printed.
对于$(ps -ex | awk'{print $ 1}')中的f;回显$ f; pfiles $ f | grep PORTNUM;完毕
切换PORTNUM为端口号。 :)可能是子pid,但可以使我们足够接近以找出有问题的应用程序。