码迷,mamicode.com
首页 > 编程语言 > 详细

获取连接状态数的awk数组命令

时间:2015-01-26 13:15:42      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:

awk -n|more

zhutianpeng@ztp-OptiPlex-780:~/Icpp/server$ netstat -n|more
激活Internet连接 (w/o 服务器)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp       28      0 10.8.0.171:43313        91.189.92.10:443        CLOSE_WAIT 
tcp        0      0 10.8.0.171:37374        116.213.120.232:80      ESTABLISHED
tcp       28      0 10.8.0.171:49282        91.189.92.23:443        CLOSE_WAIT 
tcp       28      0 10.8.0.171:34473        91.189.92.11:443        CLOSE_WAIT 
tcp       28      0 10.8.0.171:49286        91.189.92.23:443        CLOSE_WAIT 
tcp        0      0 10.8.0.171:36005        115.182.41.173:80       ESTABLISHED
tcp       28      0 10.8.0.171:43473        91.189.92.10:443        CLOSE_WAIT 
tcp       28      0 10.8.0.171:49284        91.189.92.23:443        CLOSE_WAIT 
tcp       28      0 10.8.0.171:34313        91.189.92.24:443        CLOSE_WAIT 
tcp       28      0 10.8.0.171:34315        91.189.92.24:443        CLOSE_WAIT 
tcp       28      0 10.8.0.171:49280        91.189.92.23:443        CLOSE_WAIT 
tcp       28      0 10.8.0.171:34471        91.189.92.11:443        CLOSE_WAIT 
tcp       28      0 10.8.0.171:43310        91.189.92.10:443        CLOSE_WAIT 
tcp       28      0 10.8.0.171:34317        91.189.92.24:443        CLOSE_WAIT 
tcp       28      0 10.8.0.171:34468        91.189.92.11:443        CLOSE_WAIT 
tcp       28      0 10.8.0.171:43311        91.189.92.10:443        CLOSE_WAIT 
tcp        0      0 10.8.0.171:24800        10.8.0.219:49201        ESTABLISHED
tcp       28      0 10.8.0.171:34319        91.189.92.24:443        CLOSE_WAIT 
tcp6       1      0 ::1:42019               ::1:631                 CLOSE_WAIT 
udp        0      0 127.0.0.1:54875         127.0.1.1:53            ESTABLISHED
提示:实际执行这条命令的时候,可能会得到上万条类似的记录,我们只取若干来举例。

awk数组获得连接数:

netstat -n|awk ‘/^tcp/{++S[$NF]}END{for(a in S)print a,"\t"S[a]}‘

 

参考:http://oldboy.blog.51cto.com/2561410/1184165

获取连接状态数的awk数组命令

标签:

原文地址:http://www.cnblogs.com/zhutianpeng/p/4248246.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!