-
-
Save wenjun1055/8131112 to your computer and use it in GitHub Desktop.
Revisions
-
spidersea renamed this gist
Dec 24, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
spidersea created this gist
Dec 24, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ #!/bin/bash iptables_ip(){ FILE=$1 egrep -iv "Baiduspider|bingbot|360Spider|JianKongBao|Ezooms|msnbot|Safari|AhrefsBot|Firefox|TurnitinBot|bot|AppleWebKit" $FILE|awk '{print $1}' |sort -n|uniq -c|sort -nr|awk '{if ($1>50) print $1" "$2}' >.tmp_ip if [ -s .tmp_ip ] then while read line do NUMBER=`echo $line|awk '{print $1}'` IP=`echo $line|awk '{print $2}'` NETMAST=`echo $IP|awk -F"." '{print $1"."$2"."$3}'` if grep -q $NETMAST allow_iplist then continue else if ! grep -q $NETMAST deny_iplist then echo $IP >>deny_iplist /sbin/iptables -A INPUT -s ${NETMAST}.0/24 -j DROP NOW_TIME=`date +"%Y%m%d %H:%M:%S"` cat .tmp_ip|mail -s "$NOW_TIME iptables stops IP list" [email protected] fi fi done <.tmp_ip fi exit 0 } iptables_ip /home/wwwroot/xxxx/log/access.log