NAME

IP::Geolocation::MMDB - Map IP addresses to country codes

VERSION

version 0.001

SYNOPSIS

use IP::Geolocation::MMDB;
my $db = IP::Geolocation::MMDB->new(file => 'GeoIP2-Country.mmdb');
my $country_code = $db->getcc('2620:fe::9');

DESCRIPTION

A Perl module that maps IP addresses to two-letter country codes such as "DE", "FR" and "US".

SUBROUTINES/METHODS

new

my $db = IP::Geolocation::MMDB->new(file => 'GeoIP2-Country.mmdb');

Returns a new database object. Dies if the specified file cannot be read.

getcc

my $country_code = $db->getcc($ip_address);

Takes an IPv4 or IPv6 address as a string and returns a two-letter country code or the undefined value. Dies if the address is not a valid IP address.

record_for_address

my $lookup_result = $db->record_for_address($ip_address);

Takes an IPv4 or IPv6 address as a string and returns the data associated with the IP address or the undefined value. Dies if the address is not a valid IP address.

version

my $version = IP::Geolocation::MMDB->version;

Returns the libmaxminddb version.

DIAGNOSTICS

Couldn't open database file

The database file could not be read.

Couldn't parse IP address

A string did not contain a valid IP address.

Couldn't look up IP address

A database error occurred while looking up an IP address.

Couldn't read data for IP address

A database error occurred while reading the data associated with an IP address.

CONFIGURATION AND ENVIRONMENT

None.

DEPENDENCIES

Requires Alien::libmaxminddb from CPAN. On Windows, Alien::MSYS needs to be installed.

Requires an IP to country database in the MaxMind DB file format from DP-IP.com or MaxMind.

INCOMPATIBILITIES

None.

AUTHOR

Andreas Vögele <voegelas@cpan.org>

BUGS AND LIMITATIONS

libmaxminddb uses 64-bit integers.

The data type MMDB_DATA_TYPE_UINT128 is currently not mapped to a number.

LICENSE AND COPYRIGHT

Copyright 2021 Andreas Vögele

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.