IP::Country::DB_File::Builder - Build an IP address to country code database
version 3.03
use IP::Country::DB_File::Builder; IP::Country::DB_File::Builder->fetch_files(); my $builder = IP::Country::DB_File::Builder->new('ipcc.db'); $builder->build(); IP::Country::DB_File::Builder->remove_files();
This module builds the database used to lookup country codes from IP addresses with IP::Country::DB_File.
The database is built from the publically available statistics files of the Regional Internet Registries. Currently, the files are downloaded from the following hard-coded locations:
ftp://ftp.arin.net/pub/stats/arin/delegated-arin-extended-latest ftp://ftp.ripe.net/pub/stats/ripencc/delegated-ripencc-extended-latest ftp://ftp.afrinic.net/pub/stats/afrinic/delegated-afrinic-extended-latest ftp://ftp.apnic.net/pub/stats/apnic/delegated-apnic-extended-latest ftp://ftp.lacnic.net/pub/stats/lacnic/delegated-lacnic-extended-latest
You can build the database directly from Perl, or by calling the build_ipcc.pl command. Since the country code data changes occasionally, you should consider updating the database from time to time. You can also use a database built on a different machine as long as the libdb versions are compatible.
build_ipcc.pl
my $builder = IP::Country::DB_File::Builder->new( [$db_file] );
Creates a new builder object and the database file $db_file. $db_file defaults to ipcc.db. The database file is truncated if it already exists.
$builder->build( [$dir] );
Builds a database from the statistics files in directory $dir. $dir defaults to the current directory.
my $num = $builder->num_ranges_v4;
Return the number of (possibly merged) IPv4 address ranges with country codes after a database build.
my $num = $builder->num_ranges_v6;
Return the number of (possibly merged) IPv6 address ranges with country codes after a database build.
my $num = $builder->num_addresses_v4;
Return the number of IPv4 addresses with country codes after a database build.
IP::Country::DB_File::Builder->fetch_files( [$dir] );
Fetches the statistics files from the FTP servers of the RIRs and stores them in $dir. $dir defaults to the current directory.
This function only fetches files and doesn't build the database yet.
IP::Country::DB_File::Builder->remove_files( [$dir] );
Deletes the previously fetched statistics files in $dir. $dir defaults to the current directory.
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.