*/10 * * * * /win/sh/fang_bao_pojie.sh
#!/bin/bash
cat /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print $2"=" $1;}' >/home/Denyhosts/Denyhosts.txt
#大于等于5次 就封禁 ip
DEFINE="5"
for i in `cat /home/Denyhosts/Denyhosts.txt`
do
IP=`echo $i|awk -F= '{print $1}'`
NUM=`echo $i|awk -F= '{print $2}'`
if [ $NUM -gt $DEFINE ]
then
ipExists=`grep $IP /etc/hosts.deny |grep -v grep |wc -l`
if [ $ipExists -lt 1 ]
then
echo "sshd:$IP" >> /etc/hosts.deny
fi
fi
done
如果想再次放开,清空/var/log/secure 的IP记录 和/home/Denyhosts/Denyhosts.txt