Geo::IPfree

TriggerTek Logo
abcdefghijklmnopqrstuvwxyz_
Geo::IPfree(3)	     User Contributed Perl Documentation       Geo::IPfree(3)



NAME
       Geo::IPfree - Look up country of IP Address. This module make this
       off-line and the DB of IPs is free & small.

SYNOPSIS
	   use Geo::IPfree;
	   my ($country,$country_name) = Geo::IPfree::LookUp("192.168.0.1");

	   ... or ...

	   use Geo::IPfree qw(LookUp);
	   my ($country,$country_name) = LookUp("200.176.3.142");

	   ... or ...

	   use Geo::IPfree;
	   my $GeoIP = Geo::IPfree->new(’/GeoIPfree/ipscountry.dat’);
	   $GeoIP->Faster; ## Enable the faster option.
	   my ($country,$country_name,$ip) = $GeoIP->LookUp("www.cnn.com"); ## Getting by Hostname.

	   $GeoIP->LoadDB(’/GeoIPfree/ips.dat’);

	   my ($country,$country_name,$ip) = $GeoIP->LookUp("www.sf.net"); ## Getting by Hostname.

	   ... or ...

	   use Geo::IPfree;
	   my $GeoIP = Geo::IPfree->new(); ## Using the default DB!
	   my ($country,$country_name) = $GeoIP->LookUp("64.236.24.28");

DESCRIPTION
       This package comes with it’s own database to look up the IP’s country,
       and is totally free.

METHODS
       LoadDB

       Load the database to use to LookUp the IPs.

       LookUp

       Returns the ISO 3166 country (XX) code for an IP address or Hostname.

       **If you send a Hostname you will need to be connected to the internet
       to resolve the host IP.

       Clean_Cache

       Clean the memory used by the cache.

       Faster

       Make the LookUp() faster, good for big amount of LookUp()s. This will
       load all the DB in the memory (639Kb) and read from there, not from HD
       (good way for slow HD or network disks), but use more memory. The mod-
       ule "Memoize" will be enabled for some internal functions too.

       Note that if you make a big amount of querys to LookUp(), in the end
       the amount of memory can be big, than is better to use more memory
       from the begin and make all faster.

VARS
       $GeoIP->{db}
	   The database file in use.

       $GeoIP->{handler}
	   The database file handler.

       $GeoIP->{dbfile}
	   The database file path.

       $GeoIP->{cache} BOOLEAN
	   Set/tell if the cache of LookUp() is on. If it’s on it will cache
	   the last 1000 querys. Default: 1

	   The cache is good when you are parsing a list of IPs, generally a
	   web log.  If in the log you have many lines with the same IP,
	   GEO::IPfree don’t need to make a full search for each query, it
	   will cache the last 1000 different IPs. After each 1000 IPs the
	   cache is cleaned to restart it.

	   Note that the Lookup make the query without the last IP number
	   (xxx.xxx.xxx.0), then the cache for the IP 192.168.0.1 will be the
	   same for 192.168.0.2 (they are the same query, 192.168.0.0).

DB FORMAT
       the DB has a list of IP ranges & countrys, for example, from
       200.128.0.0 to 200.103.255.255 the IPs are from BR. To make a fast
       access to the DB the format try to use less bytes per input (block).
       The file was in ASCII and in blocks of 7 bytes: XXnnnnn

	 XX    -> the country code (BR,US...)
	 nnnnn -> the IP range using a base of 85 digits
		  (not in dec or hex to get space).

       See CPAN for updates of the DB...

NOTES
       The file ipscountry.dat is made only for Geo::IPfree and has their own
       format.	To convert it see the tool "ipct2txt.pl" in the "misc" direc-
       toy.

       The module looks for "ipscountry.dat" in the following locations:

       * /usr/local/share
       * /usr/local/share/GeoIPfree
       * through @INC (as well as all @INC directories plus "/Geo")
       * from the same location that IPfree.pm was loaded

AUTHOR
       Graciliano M. P. <gm@virtuasites.com.br>

MAINTAINER
       Brian Cassidy <bricas@cpan.org>

THANK YOU
       Thanks to Laurent Destailleur (author of AWStats) that tested it on
       many OS and fixed bugs for them, like the not portable sysread, and
       asked for some speed improvement.

COPYRIGHT & LICENSE
       This program is free software; you can redistribute it and/or modify
       it under the same terms as Perl itself.



perl v5.8.8			  2009-05-11		       Geo::IPfree(3)