ip2location Extension

The ip2location converts IP addresses to location data (country/city/longitude/latitude) using services available. Supported services are MaxMind.com and ip2location.com.

Configuration

Configuration is done by overriding the 'ip2location' entry from $mydbr_defaults. As an example, add following entry with your data into the :

$mydbr_defaults['ip2location'] = [
  'default_service_provider' => 'maxmind',
  'maxmind' => [
    'account_id' => 12345,
    'license_key' => 'abcdefg'
  ],
  'ip2location' => [
    'api_key' => '12345',
    'package' => 'WS6'
  ],
  'ipinfo' => [
    'token' => '123456'
  ]
];

Commands

dbr.ip2location - Get IP location
dbr.ip2location.language - Maxmind can return names in different languages. If you wish to use other than English (code = 'en'), see supported languages from MaxMind

Syntax

select 'dbr.ip2location', 'save_procedure_name'[, 'maxmind' | 'ip2location' | 'ipinfo' ]
select 'dbr.ip2location.language', language_code

Usage

The Save Procedure

The save procedure and allows you to save the data into desired location. The procedure has format of:

create procedure sp_geo_save_ip ( 
in_ip_address varchar(39),
in_country varchar(255),
in_city varchar(255),
in_latitude decimal(11,7),
in_longitude decimal(11,7),
in_isp varchar(255),
)
begin

insert ignore into my_ip2_location(ip_address, country, city , latitude, longitude, isp)
values ( in_ip_address, in_country, in_city , in_latitude, in_longitude, in_isp );

end

Convert IP Addresses

select 'dbr.ip2location', 'sp_geo_save_ip';

select ip_address
from mydata;

Choose the Service to Use

select 'dbr.ip2location', 'sp_geo_save_ip', 'maxmind';

select ip_address
from mydata;

select 'dbr.ip2location', 'sp_geo_save_ip', 'ip2location';

select ip_address
from mydata;

select 'dbr.ip2location', 'sp_geo_save_ip', 'ipinfo';

select ip_address
from mydata;