#!/bin/sh
lastdate=`/bin/date -d last-minute +%Y%m%d`
IP_LIST_FILE=/home/liyan/deny.txt
/bin/cat /opt/web_logs/access_$lastdate.log |awk '{print $1}' |sort |uniq -c|sort -nr|head -n 10 |awk '{if($1>5000) {print $2} }' >$IP_LIST_FILE
#sort /home/liyan/temp.txt |uniq >/home/liyan/deny.txt
#list=`/bin/awk -v RS="" '{gsub("\n"," ");print}' /home/liyan/deny.txt`
#/bin/sed -i "2cDeny from $list" /home/liyan/xy.txt
IPTABLES_BIN=/sbin/iptables
BAD_IP_ADDR_LIST=$(grep -Ev "^#" $IP_LIST_FILE)
for i in $BAD_IP_ADDR_LIST
do
echo -n "Blocking $i ...";
$IPTABLES_BIN -D INPUT -s $i -j DROP
$IPTABLES_BIN -D OUTPUT -d $i -j DROP
$IPTABLES_BIN -A INPUT -s $i -j DROP
$IPTABLES_BIN -A OUTPUT -d $i -j DROP
echo "DONE.";
done
linux中将爬虫抓取的ip自动用iptables封闭。
姓名 | |
邮箱 | |
URL | |
学习了[em04]
很有用,赞一下
很有用,赞一下
没怎么看懂的赶脚