Thursday, April 19, 2012

Can I ban or restrict a country based on IP?


I get 6-10 sign ups from places like Nigeria and Ghana in Africa. I'm currently capturing IPs so is it possible to restrict a range of IPs from a specific country?



If I can retrict them does it make more sense to add this range to my .htaccess file or restrict them at the site level?


Source: Tips4all

4 comments:

  1. You can get the maxmind database:

    http://www.maxmind.com/app/mod_geoip

    and use this code:

    GeoIPEnable On
    GeoIPDBFile /path/to/GeoIP.dat

    # Redirect multiple countries to a single page
    RewriteEngine on
    RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(NI|GH)$
    RewriteRule ^(.*)$ - [F]

    ReplyDelete
  2. Yes, you can. Use GEOIP. http://www.maxmind.com/app/php

    http://www.maxmind.com/app/mod_geoip

    ReplyDelete
  3. Just google for GEOIP - there's a number of free services available you can also get a file, containing Country specific IP patterns. No services will give you 100% protection as it's possible to forge the IP.

    ReplyDelete
  4. Using Apache's mod_geoip:


    GeoIPEnable On
    GeoIPDBFile /path/to/GeoIP.dat

    SetEnvIf GEOIP_COUNTRY_CODE US BlockCountry
    # ... place more countries here

    Deny from env=BlockCountry

    ReplyDelete