首页 > 代码库 > 获取连接状态数的awk数组命令
获取连接状态数的awk数组命令
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 ESTABLISHEDtcp 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 ESTABLISHEDtcp 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 ESTABLISHEDtcp 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数组命令
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。