SHELL脚本:Dos 攻击防范(自动屏蔽 IP)

#!/bin/bash
DATE=`date +%d/%b/%Y:%H:%M`
LOG_FILE=/var/log/httpd/access_log
【SHELL脚本:Dos 攻击防范(自动屏蔽 IP)】ABNORMAL_IP=`tail -n 1000 $LOG_FILE |grep $DATE |awk '{a[$1]++}END{for(i in a) if(a[i]>10) print i}'`
for IP in $ABNORMAL_IP
do
if [ $(firewall-cmd --list-all |grep -c "$IP") -eq 0 ]
then
firewall-cmd --add-rich-rule="rule family=ipv4 source address='$IP' drop"
echo "$(date +'%F %T') $IP" >> /tmp/drop_ip.log
fi
done




    推荐阅读