实现代码:

复制代码 代码如下: #!/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,这样就会把访问量过高的IP加入防火墙,并禁止访问

您可能感兴趣的文章:

声明:本站(华域联盟www.cnhackhy.com)所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。