Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save eayoungs/302a30b9049a49efb8f2f904e7b7bf14 to your computer and use it in GitHub Desktop.
Save eayoungs/302a30b9049a49efb8f2f904e7b7bf14 to your computer and use it in GitHub Desktop.
btmp iptables drop
#!/bin/bash
TODAY=`date +'%b %e'`
WINNERS=`sudo lastb -a -10000 | grep "$TODAY" | awk '{print $10}' | sort | uniq -c| sort -n | tail -10`
echo WINNERS for $TODAY
OLDIFS="$IFS"
IFS=$'\n'
for i in $WINNERS
do
echo $i
i2=$(echo -e "${i}" | sed -e 's/^[[:space:]]*//')
count=$(echo $i2 | cut -f1 -d' ')
badhost=$(echo $i2 | cut -f2 -d' ')
if [[ $count -ge 200 ]]
then
echo iptables -A INPUT -s $i -j DROP
fi
done
IFS="$OLDIFS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment