Block Country Script

This script only runs as root and allow you to block country via IPTables.



As you see below in COUNTRIES = I have already input country ISO code which are the TOP countries known for Fraud such as Ghana.



Search on Google and add more ISO country code and run this script your server will be protected by those MOTHER F**** FRAUD people. I HATE aLL OF THEM I DONT KNOW WHy they do those things, but anyway here is your script.




#!/bin/bash
###BLOGAMA.ORG###

###PUT HERE COMA SEPARATED LIST OF COUNTRY CODE###
COUNTRIES="GH NE MK"
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 -f $WORKDIR/iptables-blocklist.txt

You can’t be serious! Do you have any idea how much memory you’ll use or what the performance impact is trying to block IP lists of whole countries?



Not only that, IP’s continuously change so you would have to rebuild your tables frequently.



There is a better way! :wink:



Get the “C Library” for GeoIP from Maxmind



Get the Apache module for GeoIP from Maxmind



Update the GeoIP database



Once installed (takes only like 5 minutes) then you can block any country you

like and don’t need any IP addresses whatsoever!



All visitors have additional variables attached beyond their IP that includes country and continent and all scripts have access to this information as does .htaccess!



I can block 10 different countries on my server with a single command and not

have to worry about keeping up with thousands of IP blocks or loading down

my server from putting in too many iptable or dead routing blocks! :wink:

geoip is already installed as part of CS-Cart as I recall under “Access Restrictions”