Skip to content

Instantly share code, notes, and snippets.

@thimslugga
Last active December 30, 2016 21:08
Show Gist options
  • Save thimslugga/8aa96ddc6f69ead068e8d9c5af62baff to your computer and use it in GitHub Desktop.
Save thimslugga/8aa96ddc6f69ead068e8d9c5af62baff to your computer and use it in GitHub Desktop.
update spamhaus list tweaked
#!/bin/vbash
NETGROUP="SPAMHAUS_DROP"
>/tmp/block
curl -s http://www.spamhaus.org/drop/drop.txt | grep '^[0-9]' | sed -e 's/;.*//' >> /tmp/block
curl -s http://www.spamhaus.org/drop/edrop.txt | grep '^[0-9]' | sed -e 's/;.*//' >> /tmp/block
sudo ipset -q -L $NETGROUP > /dev/null 2>&1
if [ "$?" != 0 ]; then
echo "firewall network group $NETGROUP doesn't exist yet"
exit 1
fi
NEWGROUP=$NETGROUP-$$
sudo ipset create $NEWGROUP hash:net
if [ "$?" != 0 ]; then
echo "There was an error trying to create temporary set"
exit 1
fi
count=0;
for i in `cat /tmp/block`;
do
sudo ipset -exist -quiet -A $NEWGROUP $i
if [ "$?" != 0 ]; then
echo "There was an error trying to add $i"
exit 1
fi
let "count++"
done
sudo ipset swap $NEWGROUP $NETGROUP
if [ "$?" != 0 ]; then
echo "There was an error trying to swap temporary set"
exit 1
fi
sudo ipset destroy $NEWGROUP
rm /tmp/block
echo Added $count entries to $NETGROUP;
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment