Skip to content

Instantly share code, notes, and snippets.

@aelindeman
Created May 17, 2016 01:43
Show Gist options
  • Save aelindeman/2b8236693c99e426d0bd95b52fbb318d to your computer and use it in GitHub Desktop.
Save aelindeman/2b8236693c99e426d0bd95b52fbb318d to your computer and use it in GitHub Desktop.
iptables cron script for Rutgers known attackers list
#!/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