View on
Graciliano Monteiro Passos > Geo-IPfree-0.2 > Geo::IPfree



Annotate this POD


Open  0
View/Report Bugs
Module Version: 0.2   Source   Latest Release: Geo-IPfree-1.151940


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


  use Geo::IPfree;
  my ($country,$country_name) = Geo::IPfree::LookUp("") ;
  ... or ...
  use Geo::IPfree qw(LookUp) ;
  my ($country,$country_name) = LookUp("") ;
  ... 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("") ; ## Getting by Hostname.
  $GeoIP->LoadDB('/GeoIPfree/ips.dat') ;
  my ($country,$country_name,$ip) = $GeoIP->LookUp("") ; ## Getting by Hostname.
  ... or ...
  use Geo::IPfree;  
  my $GeoIP = Geo::IPfree::new() ; ## Using the default DB!
  my ($country,$country_name) = $GeoIP->LookUp("") ;


  This package comes with it's own database to look up the IP's country, and is totally free.
  Take a look in CPAN for updates...



Load the database to use to LookUp the IPs.


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 the memory used by the cache.


Make the LookUp() faster, good for big amount of LookUp()s. This will load all the DB in the memory (200Kb) and read from there, not from HD (good way for slow HD or network disks), but use more memory. The module "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.



The database file in use.


The database file handler.


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 (, then the cache for the IP will be the same for (they are the same query,


the DB has a list of IP ranges & countrys, for example, from to 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...


The file ipscountry.dat is made only for Geo::IPfree and has their own format. To convert it see the tool "" in the same path of Geo/


0.2 - Sat Mar 22 18:10 2003

   - Change sysread() to read() for better portability.
   - Speed improvement for multiples LookUp().
     4 times faster!

0.01.1 - Nov 6 14:05:03 2002 (not released on CPAN)

   - Fix seek bug for Perl 5.6.0 on multiples LookUp().


Graciliano M. P. <>.

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.


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

syntax highlighting: