netstat -an | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
查看系統tcp鏈接中各個狀態的鏈接數。shell
netstat -an |grep 80 |grep ESTA |awk '{print$5 "\n"}' |awk 'BEGIN {FS=":"} {print $1 "\n"}' |sort |uniq
查看和本機80端口創建鏈接並狀態在established的全部iptcp
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);}'
輸出每一個ip的鏈接數,以及總的各個狀態的鏈接數code