Linux 查看连接数命令:1 netstat -n | awk ‘/^tcp/ {n=split($(NF-1),array,”:”);if(n<=2)++S[array[(1)]];else++S[array[(4)]];++s[$NF];++N} END {for(a in S){printf(“%-20s %s\n”, a, S[a]);++I}printf(“%-20s %s\n”,”TOTAL_IP”,I);for(a in s) printf(“%-20s %s\n”, a, s[a]);printf(“%-20s %s\n”,”TOTAL_LINK”,N);}’
显示结果:
2 TOTAL_IP 2567
3 LAST_ACK 1252
4 SYN_RECV 434
5 CLOSE_WAIT 1145
6 ESTABLISHED 3601
7 FIN_WAIT1 261
8 FIN_WAIT2 26
9 CLOSING 2
10 SYN_SENT 1864
11 TIME_WAIT 2494
12 TOTAL_LINK 11079