这是对前一篇的补充,前一篇只是正对某一个IP进行统计,这个则是统计出所有的连接数
#!/bin/sh
#current connectons report
usage()
{
echo "examples:"
echo "conns"
echo "conns -d"
exit 1
}
if [ $# -ge 2 ];then
usage
fi
if [ $# -eq 0 ];then
netstat -an | awk '{print substr($4,1,index($4,":")-1),substr($5,1,index($5,":")-1)}' | sort | uniq -c | head
fi
if [ $# -eq 1 ];then
netstat -an | awk '{print substr($4,1,index($4,":")-1),substr($5,1,index($5,":")-1)}' | sort | uniq -c
fi
本文介绍了一个简单的Shell脚本,用于统计当前系统的所有网络连接数。通过netstat命令获取连接信息,并利用awk进行字段提取,最后使用sort和uniq完成连接数统计。
2679

被折叠的 条评论
为什么被折叠?



