#!/bin/bash
block_ip()
log=/data/logs/access_log t1=`date -d "-1 min" "+%Y:%H:%M"` #t2=$1:[0-9][0-9]
egrep "$t1:[0-9]+" $log >/tmp/tmp_lastmin.log awk ‘print $1‘ /tmp/tmp_lastmin.log|sort -n |uniq -c |sort -n |awk ‘$1>100 print $2‘ >/tmp/bad_ip.list n=`wc /tmp/bad_ip.list|awk ‘print $1‘` if [ $n -ne 0 ] #if [ -s /tmp/bad_ip.list ] then for ip in `cat /tmp/bad_ip.list` do iptables -I INPUT -s $ip -j REJECT done fi
unblock_ip()
iptables -nvl INPUT |sed ‘1d‘|awk ‘$1<5 print $8‘ >/tmp/good_ip.list for ip in `cat /tmp/goog_ip.list` n=`wc /tmp/goog_ip.list|awk ‘print $1‘` if [ $n -ne 0] then for ip in `cat /tmp/good_ip.list` do iptables -D INPUT -s $ip -j REJECT done fi iptables -z
t=date "+%M" if [ $t == "00"] || [ $t == "30"] then unblock_ip block_ip else block_ip fi
|