Skip to content

Instantly share code, notes, and snippets.

@koy1619
Last active October 13, 2015 03:46
Show Gist options
  • Save koy1619/da726d0b83f87220f141 to your computer and use it in GitHub Desktop.
Save koy1619/da726d0b83f87220f141 to your computer and use it in GitHub Desktop.
Denyhosts.sh
#!/bin/bash
#Denyhosts SHELL SCRIPT
cat /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print $2"=" $1;}' >/home/sh/Denyhosts.txt
DEFINE="10"
for i in `cat /home/sh/Denyhosts.txt`
do
IP=`echo $i|awk -F= '{print $1}'`
NUM=`echo $i|awk -F= '{print $2}'`
if [ $NUM -gt $DEFINE ]
then
grep $IP /etc/hosts.deny >/dev/null
if [ $? -gt 0 ];
then
echo "sshd:$IP" >> /etc/hosts.deny
fi
fi
done
# */1 * * * * sh /home/sh/Denyhosts.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment