我没有使用awk& amp;切,请帮我解决我的问题 我有命令从每个IP地址
计算到我的服务器端口80的总连接数netstat -na|grep ":80" |awk '{print $5}'|cut -d : -f1|sort | uniq -c | sort -nr
4 173.252.80.117
4 173.252.80.116
4 173.252.80.113
2 173.252.80.119
2 173.252.80.118
2 173.252.80.115
1 66.249.64.170
1 173.252.80.114
1 173.252.80.112
我有命令列出我的服务器端口80与每个IP地址
之间的连接状态netstat -nat | grep ":80" | grep -v LISTEN | awk '{print $5 "\t" $6}' | sort | uniq -c
1 192.168.14.91:54008 TIME_WAIT
1 192.168.14.91:54009 TIME_WAIT
1 192.168.14.91:54010 TIME_WAIT
1 192.168.14.91:54011 TIME_WAIT
1 192.168.14.91:54012 TIME_WAIT
1 192.168.14.91:54013 TIME_WAIT
1 192.168.15.82:54071 ESTABLISHED
1 192.168.15.82:54072 ESTABLISHED
1 192.168.15.82:54073 ESTABLISHED
1 192.168.15.82:54074 ESTABLISHED
1 192.168.15.82:54075 ESTABLISHED
1 192.168.15.82:54076 ESTABLISHED
如何更改命令以输出:
3 192.168.14.91已建立 2 192.168.14.91 FIN_WAIT2 6 192.168.14.91 TIME_WAIT 6 192.168.15.82已建立 2 192.168.15.82 SYN_RECEIVED 6 192.168.15.82 TIME_WAIT
答案 0 :(得分:2)
by awk
netstat -nat |awk '!/LISTEN/&&/:80/{split($5,a,":");b[a[1] FS $6]++}END{for (i in b) print b[i],i}'
答案 1 :(得分:0)
更改
netstat -na |
grep ":80" |awk '{print $5}'|cut -d : -f1|sort | uniq -c
到
netstat -na |
awk -v OFS='\t' '/:80/{split($5,a,/:/); cnt[a[1]]++} END{for (ip in cnt) print cnt[ip], ip}'
和
netstat -nat |
grep ":80" | grep -v LISTEN | awk '{print $5 "\t" $6}' | sort | uniq -c
到
netstat -nat |
awk -v OFS='\t' '/:80/ && !/LISTEN/{split($5,a,/:/); cnt[a[1] OFS $6]++} END{for (ip in cnt) print cnt[ip], ip}'
和| sort -nr
根据您的喜好结束。