25 Aug 2014 17:44:47 UTC
- Distribution: IP-Country-DB_File
- Module version: 3.03
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (0)
- Testers (777 / 0 / 0)
- KwaliteeBus factor: 0
- 83.33% Coverage
- License: perl_5
- Perl: v5.8.0
- Activity24 month
- Download (16.34KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest versionNWELLNHOF Nick Wellnhofer
- 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('22.214.171.124'); 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.plor 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
EUfor Europe or
APfor 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 <email@example.com>
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.
Module Install Instructions
To install IP::Country::DB_File, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install IP::Country::DB_File
For more information on module installation, please visit the detailed CPAN module installation guide.