Linux
netstat -npt | awk 'NR>2 {++S[$1]} END {for (s in S) print s, S[s]}'
示例返回
LAST_ACK 1
SYN_RECV 10
CLOSE_WAIT 18
ESTABLISHED 9980
FIN_WAIT1 4
FIN_WAIT2 1
TIME_WAIT 2838
MacOS
netstat -n -p tcp | awk 'NR>2 {++S[$6]} END {for (s in S) print s, S[s]}'
示例返回
TIME_WAIT 15
ESTABLISHED 253