Created
October 15, 2014 13:30
-
-
Save jeffgeiger/ced8e61c4c19db806ae2 to your computer and use it in GitHub Desktop.
Update IPTables with IP's from OpenBL
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
#!/bin/bash | |
CHAINLIST=$(/sbin/iptables -nL | grep 'Chain block-traffic-from-openbl' | cut -d\ -f 2) | |
if [ -z $CHAINLIST ]; then | |
/sbin/iptables -N block-traffic-from-openbl | |
/sbin/iptables -A INPUT -j block-traffic-from-openbl | |
fi | |
BLACKLIST=$(/usr/bin/curl -fs http://www.openbl.org/lists/base_7days.txt.gz | gunzip | egrep "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}") | |
if [ $? -ne 0 ]; then | |
echo "Blacklist download failed." | |
exit | |
fi | |
/sbin/iptables -F block-traffic-from-openbl | |
IPCOUNT=$(echo $BLACKLIST | tr ' ' '\n' | wc -l) | |
echo "Adding $IPCOUNT IPs to blacklist. - $(date)" | |
echo $BLACKLIST | tr ' ' '\n' | while read -r line ; do | |
case "$line" in \#*) continue ;; esac | |
/sbin/iptables -A block-traffic-from-openbl -p tcp -s $line -j REJECT --reject-with tcp-reset | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment