Created
November 23, 2012 18:01
-
-
Save fabioadrianosoares/4136673 to your computer and use it in GitHub Desktop.
Criar regra iptables para endereco que falhar mais de 10 vezes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## [root@host]# cat procurar.sh | |
#! /bin/bash | |
tail -1000 /var/log/secure \ | |
| sed -n -e '/Failed/p' \ | |
| sed -e 's/.\+from //' -e 's/ port [0-9].\+//' \ | |
| awk '{Ip[$1]++;} END {for (var in Ip) if (Ip[var] > 10) print var;}' \ | |
| xargs -I "{}" /root/bloquear/tratar_ip.sh "{}" | |
## [root@host]# cat tratar_ip.sh | |
#! /bin/bash | |
IP=$1 | |
grep $IP /tmp/bloquear.txt > /dev/null 2>&1 | |
if [ $? == 0 ]; then | |
echo encontrou no arquivo $IP; | |
else | |
echo criar regra para ip $IP; | |
echo $IP `date` >> /tmp/bloquear.txt; | |
/sbin/iptables -A INPUT -p tcp -s $IP -j DROP; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment