- SEE ALSO
- COPYRIGHT AND LICENSE
IP::Country::DB_File - IPv4 and IPv6 to country translation using DB_File
use IP::Country::DB_File; my $ipcc = IP::Country::DB_File->new(); my $cc = $ipcc->inet_atocc('18.104.22.168'); 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.
There are many other modules for locating IP addresses. Neil Bowers posted an excellent review. Some features that make this module unique:
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
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.
** 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.
Nick Wellnhofer <firstname.lastname@example.org>
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.