CentOS中文网

CentOS防CC攻击shell脚本

CentOS中文网 https://www.centos.net.cn 2015-04-29 15:02 出处:网络 编辑:@iCMS
#!/bin/sh cd/var/log/httpd/ cataccess_log|awk'{print$1}'|sort|uniq-c|sort-n-r|head-n20>a cp/dev/nullaccess_log

#!/bin/sh

cd /var/log/httpd/

cat access_log|awk '{print $1}'|sort|uniq -c|sort -n -r|head -n 20 > a

cp /dev/null access_log

cp /dev/null error_log

cp /dev/null limit.sh

cp /dev/null c

#awk '{print $2}' a|awk -F. '{print $1"."$2"."$3}'|sort|uniq > b

cat a|while read num ip

do

if [ "$num" -gt "20" ]

then

echo $ip >> c

fi

done

cat c|awk -F. '{print $1"."$2"."$3}'|sort|uniq > b

#cat c|sort|uniq > b

for i in `cat b`

#cat b|sed 's/./ /g'|while read i1 i2 i3 i4

do

if `cat ourip |grep $i > /dev/null 2>&1`

then

echo "`date` $i" >> test

else

echo "iptables -I INPUT -p tcp -dport 80 -s $i.0/24 -j DROP" >> limit.sh

fi

done

运行命令:sh limit.sh

0

精彩评论

暂无评论...
验证码 换一张
取 消