让 netstat 不显示外部地址的端口号

让 netstat 不显示外部地址的端口号

我想让 netstat 不显示外部地址上的端口号,以便我可以对其进行一些统计。这是针对 FreeBSD 系统的。

以下是输出示例。

<root>:/# netstat -an | grep .80 |head
tcp4       0      0  61.129.65.176.80      123.120.207.172.51972   ESTABLISHED
tcp4     491      0  61.129.65.176.80      171.250.180.211.51000  ESTABLISHED
tcp4     286      0  61.129.65.176.80      123.120.207.17210399     ESTABLISHED
tcp4     299      0  61.129.65.176.80      211.8.128.46.35458    ESTABLISHED
tcp4       0      0  61.129.65.176.80      123.139.147.112.62778    ESTABLISHED
tcp4     361      0  61.129.65.176.80      239.187.139.47.17607  ESTABLISHED
tcp4     509      0  61.129.65.176.80      74.74.87.36.7822   ESTABLISHED
tcp4     324      0  61.129.65.176.80      75.30.126.198.60721     ESTABLISHED
tcp4     508      0  61.129.65.176.80      149.78.116.66.12120   ESTABLISHED
tcp4     321      0  61.129.65.176.80      48.150.75.171.2617     ESTABLISHED
<root>:/# 

答案1

将此sed命令添加到管道的末尾。它会进行贪婪搜索,直到最后.并删除它及其后面的所有数字。

... | sed -e 's/^\(.*\)\.[0-9]*/\1/'

它产生:

tcp4       0      0  61.129.65.176.80      123.120.207.172   ESTABLISHED
tcp4     491      0  61.129.65.176.80      171.250.180.211  ESTABLISHED
tcp4     286      0  61.129.65.176.80      123.120.207.172     ESTABLISHED
tcp4     299      0  61.129.65.176.80      211.8.128.46    ESTABLISHED
tcp4       0      0  61.129.65.176.80      123.139.147.112    ESTABLISHED
tcp4     361      0  61.129.65.176.80      239.187.139.47  ESTABLISHED
tcp4     509      0  61.129.65.176.80      74.74.87.36   ESTABLISHED
tcp4     324      0  61.129.65.176.80      75.30.126.198     ESTABLISHED
tcp4     508      0  61.129.65.176.80      149.78.116.66   ESTABLISHED
tcp4     321      0  61.129.65.176.80      48.150.75.171     ESTABLISHED

相关内容