Skip to content

Instantly share code, notes, and snippets.

@irr
Created February 10, 2012 12:07
Show Gist options
  • Save irr/1789100 to your computer and use it in GitHub Desktop.
Save irr/1789100 to your computer and use it in GitHub Desktop.
iptables country-block2
#!/bin/bash
###PUT HERE COMA SEPARATED LIST OF COUNTRY CODE###
COUNTRIES="AK,AR"
WORKDIR="/root"
#######################################
cd $WORKDIR
wget -c --output-document=iptables-blocklist.txt http://blogama.org/country_query.php?country=$COUNTRIES
if [ -f iptables-blocklist.txt ]; then
iptables -F
BLOCKDB="iptables-blocklist.txt"
IPS=$(grep -Ev "^#" $BLOCKDB)
for i in $IPS
do
iptables -A INPUT -s $i -j DROP
iptables -A OUTPUT -d $i -j DROP
done
fi
rm $WORKDIR/iptables-blocklist.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment