ITPub博客

首页 > Linux操作系统 > Linux操作系统 > shell检测连接数最多的IP

shell检测连接数最多的IP

原创 Linux操作系统 作者:okubuntu 时间:2012-11-30 08:48:25 0 删除 编辑
#/bin/bash
date
netstat -an | grep 1088 | awk '{print $5}'>iplist.txt #按应用端口匹配
echo "************************************************"
echo "The total of connections is `netstat -an | grep -c 1088`."
echo "************************************************"
echo "The total of different types of connections:"
netstat -an | grep 1088 | awk '{count[$6]++}END{for(i in count)print i,count[i]}' | sort -nrt ' ' -k 2 #按类型显示连接
echo "************************************************"
sed -i 's/::ffff://' iplist.txt
sed -i '/^:::/d' iplist.txt
sed -i 's/:[0-9]\{4,5\}//' iplist.txt
cat iplist.txt | sort | uniq -c | sort -nr | awk '{print "IP",$2,"has",$1,"connections."}' | head -10
执行效果如图所示

a2.jpg

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26904975/viewspace-750299/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2012-06-29

  • 博文量
    1
  • 访问量
    1437