Created
September 10, 2017 16:40
-
-
Save woohooyeah/dec5fe8933aa8b85c08c8b664777d811 to your computer and use it in GitHub Desktop.
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
| ## 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