What processes are using which ports on unix?

2019-01-31 18:07发布

I need to find out what ports are attached to which processes on a Unix machine (HP Itanium). Unfortunately, lsof is not installed and I have no way of installing it.

Does anyone know an alternative method? A fairly lengthy Googling session hasn't turned up anything.

标签: hp-ux
7条回答
别忘想泡老子
2楼-- · 2019-01-31 18:24

netstat -l (assuming it comes with that version of UNIX)

查看更多
在下西门庆
3楼-- · 2019-01-31 18:25

Given (almost) everything on unix is a file, and lsof lists open files...

Linux : netstat -putan or lsof | grep TCP

OSX : lsof | grep TCP

Other Unixen : lsof way...

查看更多
女痞
4楼-- · 2019-01-31 18:26

Assuming this is HP-UX? What about the Ptools - do you have those installed? If so you can use "pfiles" to find the ports in use by the application:

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.

for f in $(ps -ex | awk '{print $1}'); do echo $f; pfiles $f | grep PORTNUM; done

switch PORTNUM for the port number. :) may be child pid, but gets you close enough to identify the problem app.

查看更多
我想做一个坏孩纸
5楼-- · 2019-01-31 18:28
netstat -ln | awk '/^(tcp|udp)/ { split($4, a, /:/); print $1, a[2]}' | sort -u

gives you the active tcp/udp ports. Then you can use the ports with fuser -n tcp or fuser -n udp, as root, and supposing that fuser is GNU fuser or has similar options.

If you need more help, let me know.

查看更多
6楼-- · 2019-01-31 18:28

Which process uses port in unix;

1. netstat -Aan | grep port

root> netstat -Aan | grep 3872

output> f1000e000bb5c3b8 tcp 0 0 *.3872 . LISTEN

2. rmsock f1000e000bb5c3b8 tcpcb

output> The socket 0xf1000e000bb5c008 is being held by proccess 13959354 (java).

3. ps -ef | grep 13959354

查看更多
成全新的幸福
7楼-- · 2019-01-31 18:42
netstat -pln

EDIT: linux only, on other UNIXes netstat may not support all these options.

查看更多
登录 后发表回答