NAME

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

SYNOPSIS

perl -MIP::Country::DB_File::Builder -e command -- -fbr
 
my $builder = IP::Country::DB_File::Builder->new('ipcc.db');
IP::Country::DB_File::Builder::fetch_files();
$ipcc->build();
IP::Country::DB_File::Builder::remove_files();

DESCRIPTION

This module builds the database used to lookup country codes from IP addresses in 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 have to build the database before you can lookup country codes. This can be done 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 geo IP source files in directory $dir. $dir defaults to the current directory. This method creates or overwrites the database file.

FUNCTIONS

The following functions are exported by default.

fetch_files

fetch_files([ $dir ]);

Fetches geo IP source files from the FTP servers of the RIR and stores them in $dir. $dir defaults to the current directory. This method requires Net::FTP.

This method only fetches files and doesn't build the database yet.

remove_files

remove_files([ $dir ]);

Deletes the previously fetched geo IP source 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

-r

remove files

-d [dir]

set directory for geo IP source 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.