使用iptables防火墙限制web的访问PV
#!/bin/bash while true;do awk '{print $1}' /tmp/test/access.log| grep -v "^$"|sort|uniq -c >/tmp/test/tmp.log exec </tmp/test/tmp.log ##读这个文件 while read line;do ##一行一行的读 ip=`echo $line|awk '{print $2}'` count=`echo $line|awk '{print $1}'` if [ $count -gt 3 ] && [ `iptables -L -n | grep "$ip"|wc -l` -lt 1 ];then iptables -I INPUT -s $ip -j DROP echo "$line is dropped" >>/tmp/test/droplist.log fi done sleep 5 done
需要三个文件:
1.access.log web的访问log文件;
2.tmp.log web的访问文件处理结果
3.droplist.log 被限制ip的记录文件