Created
January 30, 2022 06:18
-
-
Save donuts-are-good/50ded1cba42fa33238d2f1216c07c3df to your computer and use it in GitHub Desktop.
block access by country code via IP.
This file contains 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
#!/usr/bin/bash | |
# Remove existing blocklist | |
rm /tmp/geoblocklist.txt | |
# Make space for new blocklist | |
touch /tmp/geoblocklist.txt | |
# China | |
curl -k https://www.ipdeny.com/ipblocks/data/countries/cn.zone > /tmp/geoblocklist.txt | |
# India | |
curl -k https://www.ipdeny.com/ipblocks/data/countries/in.zone >> /tmp/geoblocklist.txt | |
# Russia | |
curl -k https://www.ipdeny.com/ipblocks/data/countries/ru.zone >> /tmp/geoblocklist.txt | |
# For each entry in the blocklist, add a rule to iptables. | |
for i in $(cat /tmp/geoblocklist.txt); | |
do | |
iptables -A OUTPUT -d "$i" -j DROP | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment