通过iptables防火墙降低cc攻击

来源:互联网 发布:影音先锋替代软件 编辑:程序博客网 时间:2024/06/05 19:58
#! /bin/bash
#date :20170517
#function:record tcp max numbers of connection
while true
do
  ss|awk -F "[ :]+" '{++S[$6]}END{for(key in S) print S[key],key}'|uniq -c|sort -rn -k1|head -10 >ss.txt
  while read line
     do
        ip=`echo $line|awk '{print $3}'|grep "127.0.0.1"`
        count=`echo $line|awk '{print $2}'`
        if [ $count -gt 30 ] && [ `iptables -L -n |grep "$ip"|wc -l` -lt 1 ]
        then
       iptables -I INPUT -s $ip -j DROP
       echo "$line is dropped" >>record-ip.txt
           #echo $line `date` >>record-ip.txt
        fi
     done <ss.txt
     sleep 30
done