欢迎光临
我们一直在努力

shell统计当前网络连接情况

当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

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。