标签:统计网络连接
当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
标签:统计网络连接
原文地址:http://liuzhengwei521.blog.51cto.com/4855442/1909106