【原创】lsof 命令如何显示端口名所对应的端口号?

blogdaren 2019-01-23 抢沙发 85人次

问题背景:

执行命令 lsof -ni:80,默认输出如下:

COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
php     4866 root    3u  IPv4  30639      0t0  TCP 192.168.1.234:65475->47.94.251.227:http (CLOSE_WAIT)
php     4869 root    3u  IPv4  30669      0t0  TCP 192.168.1.234:65479->47.94.251.227:http (CLOSE_WAIT)
php     4945 root    3u  IPv4  31335      0t0  TCP 192.168.1.234:65528->47.94.251.227:http (CLOSE_WAIT)

我们希望其中的47.94.251.227:http】 显示为  47.94.251.227:80】

解决方案:

#  lsof -ni:80 -P

效果图:

COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
php     4866 root    3u  IPv4  30639      0t0  TCP 192.168.1.234:65475->47.94.251.227:80 (CLOSE_WAIT)
php     4869 root    3u  IPv4  30669      0t0  TCP 192.168.1.234:65479->47.94.251.227:80 (CLOSE_WAIT)
php     4945 root    3u  IPv4  31335      0t0  TCP 192.168.1.234:65528->47.94.251.227:80 (CLOSE_WAIT)

问题补充:

From the man page, we can get this: 
-n: inhibits the conversion of network numbers to host names for network files. 
-P: inhibits the conversion of port numbers to port names for network files.

版权声明:除非注明,本文由( blogdaren )原创,转载请保留文章出处。

本文链接:【原创】lsof 命令如何显示端口名所对应的端口号?

发表评论:

您的昵称:
电子邮件:
个人主页: