IP::Country::DB_File - IPv4 and IPv6 to country translation using DB_File
version 3.03
use IP::Country::DB_File; my $ipcc = IP::Country::DB_File->new(); my $cc = $ipcc->inet_atocc('1.2.3.4'); my $cc = $ipcc->inet_atocc('host.example.com'); my $cc = $ipcc->inet6_atocc('1a00:300::'); my $cc = $ipcc->inet6_atocc('ipv6.example.com');
IP::Country::DB_File is a light-weight module for fast IP address to country translation based on DB_File. The country code database is stored in a Berkeley DB file. You have to build the database using build_ipcc.pl or IP::Country::DB_File::Builder before you can lookup country codes.
build_ipcc.pl
This module tries to be API compatible with the other IP::Country modules. The installation of IP::Country is not required.
There are many other modules for locating IP addresses. Neil Bowers posted an excellent review. Some features that make this module unique:
IPv6 support.
Pure Perl. Math::Int64 is needed to build a database with IPv6 addresses but the lookup code only uses Perl core modules.
Reasonably fast and accurate.
Builds the database directly from the statistics files of the regional internet registries. No third-party tie-in.
my $ipcc = IP::Country::DB_File->new( [$db_file] );
Creates a new object and opens the database file $db_file. $db_file defaults to ipcc.db. The database file can be built with IP::Country::DB_File::Builder or the build_ipcc.pl command.
my $cc = $ipcc->inet_atocc($host);
Looks up the country code of host $host. $host can either be an IPv4 address in dotted quad notation or a hostname.
If successful, returns the country code. In most cases this is an ISO-3166-1 alpha-2 country code, but there are also generic codes like EU for Europe or AP for Asia/Pacific. All country codes consist of two uppercase letters.
EU
AP
Returns ** for private IP addresses.
**
Returns undef if there's no country code listed for the IP address, the DNS lookup fails, or the host string is invalid.
my $cc = $ipcc->inet_ntocc($packed_address);
Like inet_atocc but works with a packed IPv4 address.
my $cc = $ipcc->inet6_atocc($host);
Like inet_atocc but works with IPv6 addresses or hosts.
my $cc = $ipcc->inet6_ntocc($packed_address);
Like inet_ntocc but works with a packed IPv6 address.
my $time = $ipcc->db_time();
Returns the mtime of the DB file.
IP::Country, IP::Country::DB_File::Builder
Nick Wellnhofer <wellnhofer@aevum.de>
This software is copyright (c) 2014 by Nick Wellnhofer.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install IP::Country::DB_File, copy and paste the appropriate command in to your terminal.
cpanm
cpanm IP::Country::DB_File
CPAN shell
perl -MCPAN -e shell install IP::Country::DB_File
For more information on module installation, please visit the detailed CPAN module installation guide.