Apache Module

This is an IP2Location Apache Module that enables the user to identify the country, region, city, latitude, longitude, zip code, time zone, ISP, domain name, connection type, area code, weather, MCC, MNC, mobile brand name, elevation and usage type by IP address. It contains a demo IP2Location IP-COUNTRY BIN database which consists of real data for IP address range 0.0.0.0 to 99.255.255.255. This database contains IP address blocks as key and countries as values. The paid version of IP2Location database covers all IP address ranges. In general, it is more complete, faster and more accurate than using reverse DNS lookups.

Developers can download other sample databases to evaluate other features such as region, city, latitude, longitude, zip code, ISP and domain name using the same Apache module.

Download IP2Location Apache Module (931.98 kB) Version: 7.0.0

 

Installation

Linux/Unix

  1. Download IP2Location C library at here.
  2. Decompress C library.
    tar xvfz ip2location-c-x.x.x.tar.gz
  3. Download and decompress Apache module.
    tar xvfz ip2location-apache-x.x.x.tar.gz
  4. Get into working directory.
    cd ip2location-apache-x.x.x
  5. Start compilation.
    apxs2 -i -a -L /usr/local/lib/ -I ../ip2location-c-x.x.x/libIP2Location/ -l IP2Location -c mod_ip2location.c
  6. Add following lines into /etc/apache2/apache2.conf
    <IfModule mod_ip2location.c>
    	IP2LocationEnable On
    	IP2LocationDetectProxy <On|Off>
    	IP2LocationSetmode <ALL>
    	IP2LocationDBFile <ip2location_binary_db_file_with_fully_qualified_path>
    </IfModule>

Windows

  1. Download IP2Location C library at here.
  2. Decompress C library using 7-zip or other compression tools.
  3. Download and decompress Apache module.
  4. Navigate to ip2location-apache-x.x.x folder.
  5. Edit Makefile.win to change the path for C library.
    IP2LOCATION_CSRC_PATH = C:/ip2location-c-x.x.x/libIP2Location
    IP2LOCATION_CLIB_PATH = C:/ip2location-c-x.x.x/libIP2Location
    APACHE_INSTALL_PATH = "C:/Program Files/Apache Software Foundation/Apachex.x"
  6. Start compilation.
    nmake /f Makefile.win
  7. Copy IP2Location_apache.dll generated to Apache modules directory.
  8. Add following lines into httpd.conf
    <IfModule mod_ip2location.c>
    	IP2LocationEnable <ON|OFF>
    	IP2LocationDetectProxy <ON|OFF>
    	IP2LocationSetmode <ALL>
    	IP2LocationDBFile <ip2location_binary_db_file_with_fully_qualified_path>
    </IfModule>

 

Module Settings
NameDescription
IP2LocationEnableON | OFF. Enable or disable the IP2Location Apache Module.
IP2LocationDetectProxyON | OFF. If enabled, the module will detect the proxy IP address from X-Forwarded-For server variable. If disabled, IP address is from REMOTE_ADDR server variable.
IP2LocationSetmodeALL | ENV | NOTES. ENV will set the environment variables; NOTES will set the Apache NOTES variables; ALL will set both the ENV and NOTES variables.
IP2LocationDBFileFull qualified path to the IP2Location BIN database file.

 

Sample Codes
RewriteEngine On
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^UK$
RewriteRule ^(.*)$ http://www.google.co.uk [L]

 

Sample IP2Location Databases (BIN)

The following evaluation copy of the database file has limited range of IP address information compare to commercial. For evaluation purpose, you can query IP addresses from 0.0.0.0-99.255.255.255 (IPv4) or 2A04:0:0:0:0:0:0:0-2A04:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF (IPv6).

Sample Packages IPv4 IPv6
IP2Location DB1 Sample Bin File338.81 kB88.24 kB
IP2Location DB2 Sample Bin File35.95 MB104.78 kB
IP2Location DB3 Sample Bin File12.25 MB95.11 kB
IP2Location DB4 Sample Bin File46.07 MB110.79 kB
IP2Location DB5 Sample Bin File18.71 MB99.57 kB
IP2Location DB6 Sample Bin File52.91 MB115.11 kB
IP2Location DB7 Sample Bin File51.30 MB118.70 kB
IP2Location DB8 Sample Bin File58.51 MB122.75 kB
IP2Location DB9 Sample Bin File21.80 MB102.04 kB
IP2Location DB10 Sample Bin File62.58 MB126.01 kB
IP2Location DB11 Sample Bin File22.22 MB102.56 kB
IP2Location DB12 Sample Bin File62.92 MB126.58 kB
IP2Location DB13 Sample Bin File19.80 MB100.28 kB
IP2Location DB14 Sample Bin File63.95 MB126.84 kB
IP2Location DB15 Sample Bin File24.20 MB105.33 kB
IP2Location DB16 Sample Bin File67.81 MB130.89 kB
IP2Location DB17 Sample Bin File24.52 MB105.64 kB
IP2Location DB18 Sample Bin File73.28 MB137.52 kB
IP2Location DB19 Sample Bin File60.49 MB123.39 kB
IP2Location DB20 Sample Bin File75.16 MB138.44 kB
IP2Location DB21 Sample Bin File26.42 MB107.07 kB
IP2Location DB22 Sample Bin File77.92 MB140.49 kB
IP2Location DB23 Sample Bin File60.92 MB123.78 kB
IP2Location DB24 Sample Bin File78.68 MB140.90 kB