转自:
http://my.oschina.net/u/162204/blog/48713
-an | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}' |
查看系统tcp连接中各个状态的连接数。
1 | netstat -an | grep 80 | grep ESTA | awk '{print$5 "\n"}' | awk 'BEGIN {FS=":"} {print $1 "\n"}' | sort | uniq |
查看和本机80端口建立连接并状态在established的所有ip
1 | netstat -n | awk '/^tcp/ {n= split ($(NF-1),array, ":" ); if (n<=2)++S[array[(1)]]; |
2 | else ++S[array[(4)]];++s[$NF];++N} END { for (a in S){ printf ( "%-20s %s\n" , a, S[a]);++I} |
3 | printf ( "%-20s %s\n" , "TOTAL_IP" ,I); for (a in s) |
4 | printf ( "%-20s %s\n" ,a, s[a]); printf ( "%-20s %s\n" , "TOTAL_LINK" ,N);}' |
输出每个ip的连接数,以及总的各个状态的连接数