Skip to content

Instantly share code, notes, and snippets.

@donuts-are-good
Created January 30, 2022 06:18
Show Gist options
  • Save donuts-are-good/50ded1cba42fa33238d2f1216c07c3df to your computer and use it in GitHub Desktop.
Save donuts-are-good/50ded1cba42fa33238d2f1216c07c3df to your computer and use it in GitHub Desktop.
block access by country code via IP.
#!/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