Skip to content

Instantly share code, notes, and snippets.

@scragg0x
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scragg0x/c47dbaab94696dc13c67 to your computer and use it in GitHub Desktop.
Save scragg0x/c47dbaab94696dc13c67 to your computer and use it in GitHub Desktop.
Geo Blocker
#!/bin/bash
if [ $# -eq 0 ]
then
echo "No arguments supplied. Example: sudo bash geo_block.sh cn af"
exit 1
fi
IPT=/sbin/iptables
IPDENY="http://www.ipdeny.com/ipblocks/data/countries"
CURL=/usr/bin/curl
CHAIN=COUNTRY
# Drop chain
iptables -D INPUT -j $CHAIN
iptables --flush $CHAIN
iptables -X $CHAIN
# Create chain
iptables -N $CHAIN
iptables -A INPUT -j $CHAIN
for c in "$@"
do
echo "Blocking $c!"
BADIPS=$($CURL -sS $IPDENY/$c.zone | egrep -v "^#|^$")
for ipblock in $BADIPS
do
$IPT -A $CHAIN -s $ipblock -j DROP
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment