Created
May 17, 2016 01:43
-
-
Save aelindeman/2b8236693c99e426d0bd95b52fbb318d to your computer and use it in GitHub Desktop.
iptables cron script for Rutgers known attackers list
This file contains 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
#!/bin/bash | |
IPTABLES=$(which iptables) | |
URL="http://report.rutgers.edu/DROP/attackers" | |
FILE="/tmp/rutgers-drop-list.txt" | |
CHAIN="RUTGERSDROP"; | |
# check if chain exists | |
$IPTABLES -L $CHAIN -n | |
if [ $? -eq 0 ]; then | |
$IPTABLES -F $CHAIN | |
echo "Flushed old rules" | |
else | |
$IPTABLES -N $CHAIN | |
$IPTABLES -A INPUT -j $CHAIN | |
$IPTABLES -A FORWARD -j $CHAIN | |
echo "Creating new chain" | |
fi; | |
wget -qc $URL -O $FILE | |
for IP in $(cat $FILE | egrep -v '^;' | awk '{ print $1}'); do | |
$IPTABLES -A $CHAIN -p all -s $IP -j DROP | |
echo "Added drop rule for $IP" | |
done | |
unlink $FILE | |
echo "Finished" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment