身為一個兼職網管,偶爾你總想找出到底是那一隻程式佔用了網路埠、或是找出某個連線是哪隻程式建立的。在 FreeBSD 上有一個工具非常好用,叫做 sockstat。但是 Linux 過去一直沒有人寫這樣的工具,你可以用 ‘lsof -i -n’ 或是 ‘netstat -anpe‘ 等指令來滿足這個需求。
最近 William Pitcock (nenolod) 重新改寫了一版給 Linux 用的 sockstat,目前已經進入 Debian Sid 中。
需要者請自行取用吧。
$ sockstat USER PROCESS PID PROTO SOURCE ADDRESS FOREIGN ADDRESS STATE chihchun conduit.real 7902 tcp4 *:3400 *: * LISTEN chihchun dropboxd 7989 tcp4 10.11.12.231:49912 75.126.170.58:443 CLOSE_WAIT chihchun dropboxd 7989 tcp4 10.11.12.231:44740 174.36.30.10:80 ESTABLISHED chihchun pidgin 8651 tcp4 10.11.12.231:34182 140.112.101.236:5222 ESTABLISHED chihchun pidgin 8651 tcp4 10.11.12.231:57405 72.14.235.125:5222 ESTABLISHED chihchun pidgin 8651 tcp4 10.11.12.231:35309 207.46.26.76:1863 ESTABLISHED chihchun pidgin 8651 tcp4 10.11.12.231:43043 207.46.111.14:1863 ESTABLISHED chihchun pidgin 8651 tcp4 10.11.12.231:46378 66.163.181.178:5050 ESTABLISHED chihchun skype 8653 udp4 127.0.0.1:43150 *: * CLOSED chihchun skype 8653 tcp4 *:14339 *: * LISTEN chihchun skype 8653 udp4 *:14339 *: * CLOSED chihchun skype 8653 tcp4 10.11.12.231:56172 59.127.108.65:26929 ESTABLISHED chihchun xchat 21275 tcp4 127.0.0.1:54522 127.0.0.1:6667 ESTABLISHED chihchun xchat 21275 tcp4 127.0.0.1:54523 127.0.0.1:6667 ESTABLISHED chihchun xchat 21275 tcp4 127.0.0.1:54524 127.0.0.1:6667 ESTABLISHED chihchun ssh 22871 tcp4 127.0.0.1:6667 *: * LISTEN chihchun ssh 22871 tcp4 127.0.0.1:6667 127.0.0.1:54522 ESTABLISHED chihchun ssh 22871 tcp4 127.0.0.1:6667 127.0.0.1:54523 ESTABLISHED chihchun ssh 22871 tcp4 127.0.0.1:6667 127.0.0.1:54524 ESTABLISHED chihchun ssh 28346 tcp4 10.11.12.231:51441 163.16.211.21:22 ESTABLISHED chihchun ssh 28346 tcp4 127.0.0.1:1100 *: * LISTEN chihchun ssh 28346 tcp4 127.0.0.1:2500 *: * LISTEN