19 Jan 2011 23:22:46 UTC
- Distribution: IP-Country-DB_File
- Module version: 2.01
- Source (raw)
- Browse (raw)
- How to Contribute
- Clone repository
- Issues (0)
- Testers (304 / 14 / 0)
- KwaliteeBus factor: 1
- License: perl_5
- Activity24 month
- Download (13.86KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest versionNWELLNHOF Nick Wellnhofer
- OBJECT METHODS
- COPYRIGHT AND LICENSE
IP::Country::DB_File::Builder - Build an IP address to country code database
perl -MIP::Country::DB_File::Builder -e command -- -fbr use IP::Country::DB_File::Builder; fetch_files(); my $builder = IP::Country::DB_File::Builder->new('ipcc.db'); $builder->build(); 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-latest ftp://ftp.ripe.net/pub/stats/ripencc/delegated-ripencc-latest ftp://ftp.afrinic.net/pub/stats/afrinic/delegated-afrinic-latest ftp://ftp.apnic.net/pub/stats/apnic/delegated-apnic-latest ftp://ftp.lacnic.net/pub/stats/lacnic/delegated-lacnic-latest
You can build the database directly in Perl, or by calling the command subroutine from the command line. Since the country code data changes constantly, 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.
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.
The following functions are exported by default.
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 requires Net::FTP.
This function only fetches files and doesn't build the database yet.
remove_files([ $dir ]);
Deletes the previously fetched statistics files in $dir. $dir defaults to the current directory.
You can call this subroutine from the command line to update the country code database like this:
perl -MIP::Country::DB_File::Builder -e command -- [options] [dbfile]
dbfile is the database file and defaults to ipcc.db. Options include
directory for the statistics files
You should provide at least one of the -f, -b or -r options, otherwise this routine does nothing.
Nick Wellnhofer <firstname.lastname@example.org>
This software is copyright (c) 2011 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.