How to avoid blocking customers in your own country

ANytech

New member
Joined
Mar 18, 2014
Messages
1
One of the most time consuming things (especially for me) is unblocking customers who have blocked themselves.
If most of your customers are in the same country and you don't get many (if any) attacks from your location you can do the following:

Presuming you have followed I wish to have a block_ip.sh so I can block IPs through DirectAdmin: http://help.directadmin.com/item.php?id=380

First install GeoIPlookup: http://kbeezie.com/geoiplookup-command-line/

Locate the file: /usr/local/directadmin/scripts/custom/block_ip.sh

Underneath the following:
Code:
### Make sure it's not alreaday blocked
COUNT=`grep -c "^${ip}=" $BF`;
if [ "$COUNT" -ne 0 ]; then
	echo "$ip already exists in $BF ($COUNT). Not blocking.";
	curriptables
	exit 2;
fi
Place something like this:
Code:
################### Make sure it's not New Zealand! ##########

now=$(/usr/bin/geoiplookup $ip)
if [[ $now == *NZ* ]]; then
  	echo "This is a New Zealand ip address - Not Blocking";
	curriptables
	exit 2;
fi

##############################################################
Obviously change the settings to the country you desire and you will now not automatically block the country specified (failures will still be logged).
 

SeLLeRoNe

Super Moderator
Joined
Oct 9, 2004
Messages
6,797
Location
A Coruña, Spain
Nice one.

Thanks for sharing.

for who is using CSF a working one should be:

Code:
COUNTRY=$(/usr/bin/geoiplookup $ip)
                                                                                                                                                                                        
if [[ $COUNTRY != *YOUR_CONTRY* ]]; then
                                                                                                                                                                                        
        /etc/csf/csf.pl -d $ip BFM IP Block
                                                                                                                                                                                        
fi
Of course, be sure to change YOUR_COUNTRY with your correct Country

Regards
 
Top