NAME

SYNOPSIS

DESCRIPTION

IP::World returns the ISO-3166 country code associated with an IP4 address. This version is based on two free databases from http://www.wipmania.com and http://www.maxmind.com. An included application checks the currency of the included database on installation, and can be scheduled to do so periodically.

The author uses this package for customizing served web pages to the location of the visitor, particularly to quote prices of items for sale in the visitor's currency. Also for server log analysis.

EXPORTS

You can optionally export some constants (the IP_WORLD_* constants listed below) when you 'use' the module. For example:

use IP::World qw(IP_WORLD_TINY_PERL);

METHODS

new

$ipw = IP::World->new($mode);

In object-oriented terms, this is a constructor. It returns a scalar object that's used in calling the getcc method as described below.

$mode is optional and selects the operating mode:

0 or IP_WORLD_FAST

fast, keeps data in memory (643 KB at initial release, but who cares these days?) This is the default.

1 or IP_WORLD_MMAP

Mmap, keeps data in Mmap memory, may reduce total memory requirement of sibling processes. If your system doesn't support Mmap, 1 operates like 0.

tiny PerlIO, slow but saves memory by searching the database on disk using Perl I/O calls. If your system doesn't support Perl I/O, 3 works like 2. If it does, performance may differ between this option and the preceding one.

getcc

$ccod = $ipw->getcc($ipad);

$ipad should contain an IP4 address in one of two formats:

a dotted quad string like '13.117.255.3'

a 4-byte packed binary string produced by inet_aton or pack('C4', four values 0-255)

** indicates that $ipad was not in either of the two formats described above.

?? indicates that the database doesn't include a mapping for the IP address.

SCRIPTS

Three Perl scripts are installed with IP::World:

maint_ip_world_db

The application checks whether new data is available from either data source. If there is, it downloads the data and builds a new database.

You can run this manually to check for a new database, or (on a server or other 24/7 system) you can schedule it for automatic execution at a non-busy time.

In either case you should run maint_ip_world_db with privilege to rewrite the database file. For Unix/Linux systems this means running it as root, such as by entering the command sudo maint_ip_world_db.

During installation, you will be asked if a command should be executed by maint_ip_world_db when a new database has been created (e.g., to restart a web server that uses the database).

The install process for IP::World runs maint_ip_world_db to ensure that the most recent data is installed.

ip_world_dump

Lists the database created by maint_ip_world_db.

ip_cc_benchmark

Compares the performance of IP::World with that of similar modules.

PERFORMANCE

ip-benchmark showed the following results in one run on the author's server:

This program is distributed in the hope that it will be useful, but it is provided 'as is' and without any express or implied warranties. For details, see the full text of the licenses at the above URLs.

AUTHOR

Craig MacKenna <craig@animalhead.com>

SEE ALSO

The function of IP-World is almost the same as that of two other CPAN modules:

IP::Country::Fast

This module appears to have the disadvantage that its database can only be updated by re-installing the module. With IP-World, MaxMind updates its GeoIP data monthly, and WIPmania updates its WorldIP data every 2 months. Such updates are automatically downloaded if you schedule maint_ip_world_db.

Geo::IP

This uses one of the two data sources that IP-World uses. It can also use MaxMind's licensed, fee-based databases that include more data.

Unfortunately if you want this package to operate at the speeds shown in "PERFORMANCE", you have to download a C library from http://www.maxmind.com and install it from the command line. Someone should tell them about XS modules so that their whole package can be obtained from CPAN or CPANPLUS...

Module Install Instructions

To install IP::World, simply copy and paste either of the commands in to your terminal