netstat -ant|grep -v TIME_WAIT|awk -F '[[:space:]:]+' '{print $6"\t"$4":"$5}'|sort|uniq -c|sort -rg|grep :5672|head -n 20
netstat -ant
打印端口使用情况|grep -v TIME_WAIT
去掉TIME_WAIT状态的连接(netstat中不加-n也可以)|awk -F '[[:space:]:]+' '{print $6"\t"$4":"$5}'
用空格和冒号拆分字符串,并重新拼接,只保留远程IP,本地IP和本地端口。- -F 设置分隔符
- {print $6} 打印第6个参数
|sort|uniq -c
先用sort排序然后通过uniq -c做分类汇总|sort -rg
重新排序|grep :5672
只找端口号为5672的|head -n 20
取前20条
netstat -ant|grep -v TIME_WAIT|awk '{match($4"\t"$5, /^([0-9\.]+:[0-9]+)\t([0-9\.]+):[0-9]+$/, a); if(a[1]) print a[2]"\t"a[1]}'|sort|uniq -c|sort -rg|grep 5672|head -n 20