The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

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

VERSION

version 3.03

SYNOPSIS

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

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-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.

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.

METHODS

build

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

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

num_ranges_v4

    my $num = $builder->num_ranges_v4;

Return the number of (possibly merged) IPv4 address ranges with country codes after a database build.

num_ranges_v6

    my $num = $builder->num_ranges_v6;

Return the number of (possibly merged) IPv6 address ranges with country codes after a database build.

num_addresses_v4

    my $num = $builder->num_addresses_v4;

Return the number of IPv4 addresses with country codes after a database build.

CLASS METHODS

fetch_files

    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.

remove_files

    IP::Country::DB_File::Builder->remove_files( [$dir] );

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

AUTHOR

Nick Wellnhofer <wellnhofer@aevum.de>

COPYRIGHT AND LICENSE

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.