统计端口调用方连接数
统计其他服务调用自己的
ss -at -o state established '( sport = :8090 )'|awk 'NR !=1 {print $4}'|column -s ':' -t|awk '{print $1}'|sort|uniq -c|sort -n- -a:全部连接
- -t:仅tcp连接
- -o state established:过滤只保留活跃连接
- ( sport = :8090 ):仅保留服务端8090端口
- awk NR!=1 不要标题行
- {print $4} 只保留第四列(客户端ip和端口)
- column -s ':' -t 按冒号切割(ip:port)
- awk '{print $1}' 只保留第一列(只保留ip)
- sort:排序
- uniq -c:汇总每个ip的数量(需要先排序后汇总)
- sort -n 按count数排序
统计自己调用其他服务的
ss -at -o state established '( sport != :8090 )'|awk 'NR !=1 {print $4}'|sort|uniq -c|sort -n