Skip to content

Instantly share code, notes, and snippets.

@woohooyeah
Created September 10, 2017 16:40
Show Gist options
  • Select an option

  • Save woohooyeah/dec5fe8933aa8b85c08c8b664777d811 to your computer and use it in GitHub Desktop.

Select an option

Save woohooyeah/dec5fe8933aa8b85c08c8b664777d811 to your computer and use it in GitHub Desktop.
## insert-spammers-into-ip6tables.sh v0.1
## Dorian Harmans <[email protected]>
##
#!/bin/bash
if [ -e /root/spammers-ipv6.txt ]; then
/sbin/ip6tables-save > /root/ip6tables.rules && cp /root/ip6tables.rules /root/ip6tables.rules-old
else
echo -e "Failed!\nReason: /root/spammers.txt not found"
exit 1
fi
if [ -e /root/ip6tables.rules ]; then
grep -E "(-A INPUT -s | -j DROP)" /root/ip6tables.rules | awk '{ print $4 }' > /root/ip6-blocklist-old.txt
grep -vE "(-A INPUT -s | -j DROP)" /root/ip6tables.rules > /root/ip6tables.rules-clean
else
echo -e "Failed!\nReason: /root/ip6tables.rules not found"
exit 1
fi
if [ -e /root/ip6tables.rules-clean ]; then
/sbin/ip6tables-restore < /root/ip6tables.rules-clean
else
echo -e "Failed!\nReason: /root/ip6tables.rules-clean not found"
exit 1
fi
if [ -e /root/spammers-ipv6.txt ]; then
for line in $(cat /root/spammers-ipv6.txt); do /sbin/ip6tables -A INPUT -s $line/128 -j DROP; done
else
echo -e "Failed!\nReason: /root/spammers-ipv6.txt not found"
exit 1
fi
if [ -e /root/ip6tables.rules ]; then
/sbin/ip6tables-save > /etc/ip6tables.rules && /sbin/ip6tables-save > /root/ip6tables.rules-new
grep -E "(-A INPUT -s | -j DROP)" /root/ip6tables.rules-new | awk '{ print $4 }' > /root/ip6-blocklist-new.txt
else
echo -e "Failed!\nReason: /root/ip6tables.rules-new not found"
exit 1
fi
if [ -e /root/ip6-blocklist-old.txt ] && [ -e /root/ip6-blocklist-new.txt ]; then
diff -Naur /root/ip6-blocklist-old.txt /root/ip6-blocklist-new.txt
else
echo -e "Failed!\nReason: /root/ip6-blocklist-{old,new} not found"
exit 1
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment