全部博文(78)
分类:
2009-11-17 22:16:04
#!/bin/sh
IPTABLES=/sbin/iptables
time1=`date |awk '{print $4}'|awk -F ':' '{print$1":"$2}'`
ss=`date |awk '{print $4}'|awk -F ':' '{print$3}'`
sd=`date |awk '{print $4}'|awk -F ':' '{print$3}'|sed 's/\([0-9]\)[0-9]/\1\*/'`
sleep 20
time2=`date |awk '{print $4}'|awk -F ':' '{print$1":"$2}'`
sd2=`date |awk '{print $4}'|awk -F ':' '{print$3}'|sed 's/\([0-9]\)[0-9]/\1\*/'`
echo $time1
echo $ss
echo $sd
echo $time2
echo $sd2
log=/usr/local/apache2/logs/access_log
#mess=`tail -n 2000 $log|sed -n "/$time1\:$sd/,/$time2\:$sd2/p"`
#echo $mess
dropip=`tail -n 2000 $log|sed -n "/$time1:$sd/,/$time2:$sd2/p" |awk '{++a[$1]}END{for (i in a) print i":"a[i]}'|awk -F ':' '{if($2>=
12)print $1}'|sed -n '1p'`
#echo $dropip
if [ -n "$dropip" ]
then
#echo $dropip
echo `date` >>/home/chenjl/dropip
echo $dropip >>/home/chenjl/dropip
$IPTABLES -I INPUT -s $dropip -j REJECT
else
echo `date` >>/home/chenjl/dropip
echo ok >>/home/chenjl/dropip
fi