NAME

IP::Country::DB_File::Builder - Build an IP address to country code database

SYNOPSIS

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();

DESCRIPTION

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.

CONSTRUCTOR

new

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.

OBJECT METHODS

build

$builder->build([ $dir ]);

Builds a database from the statistics files in directory $dir. $dir defaults to the current directory.

FUNCTIONS

The following functions are exported by default.

fetch_files

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

remove_files([ $dir ]);

Deletes the previously fetched statistics files in $dir. $dir defaults to the current directory.

command

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

-f

fetch files

-b

build database

-v

verbose output

-r

remove files

-d [dir]

directory for the statistics files

You should provide at least one of the -f, -b or -r options, otherwise this routine does nothing.

AUTHOR

Nick Wellnhofer <wellnhofer@aevum.de>

COPYRIGHT AND LICENSE

Copyright (C) Nick Wellnhofer, 2009

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.6.0 or, at your option, any later version of Perl 5 you may have available.