Last active
August 29, 2015 14:04
-
-
Save scragg0x/c47dbaab94696dc13c67 to your computer and use it in GitHub Desktop.
Geo Blocker
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
#!/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