码迷,mamicode.com
首页 > 系统相关 > 详细

shell统计当前网络连接情况

时间:2017-03-22 11:43:13      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:统计网络连接

当TCP连接数量非常大时,对当前的内部IP,外部IP的连接情况进行统计

[root@lvs02 account_tcp]# cat account_tcp.sh 
#!/bin/bash
#统计当前网络连接情况
netstat -na | awk ‘/^tcp/{s[$6]++}END{for(key in s)print key,s[key]}‘ > /root/account_tcp/state.txt
#统计Local Address的TCP连接数
netstat -na | awk ‘/^tcp/‘ | awk -v FS="[ :]+" ‘{print $4}‘ | sort | uniq -c | sort -n > /root/account_tcp/Local_Address.txt
#统计IP为51的Foreign Address的TCP连接情况
netstat -na | awk ‘/^tcp/‘ | grep 192.168.10.51 | awk -v FS="[ :]+" ‘{print $6}‘ | sort | uniq -c | sort -n > /root/account_tcp/51_tcp.txt
#统计IP为80的Foreign Address的TCP连接情况
netstat -na | awk ‘/^tcp/‘ | grep 192.168.10.80 | awk -v FS="[ :]+" ‘{print $6}‘ | sort | uniq -c | sort -n > /root/account_tcp/80_tcp.txt
#统计IP为86的Foreign Address的TCP连接情况
netstat -na | awk ‘/^tcp/‘ | grep 192.168.10.86 | awk -v FS="[ :]+" ‘{print $6}‘ | sort | uniq -c | sort -n > /root/account_tcp/86_tcp.txt
#统计IP为87的Foreign Address的TCP连接情况
netstat -na | awk ‘/^tcp/‘ | grep 192.168.10.87 | awk -v FS="[ :]+" ‘{print $6}‘ | sort | uniq -c | sort -n > /root/account_tcp/87_tcp.txt


本文出自 “激情燃烧的岁月” 博客,请务必保留此出处http://liuzhengwei521.blog.51cto.com/4855442/1909106

shell统计当前网络连接情况

标签:统计网络连接

原文地址:http://liuzhengwei521.blog.51cto.com/4855442/1909106

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