- IP ADDRESS TO COUNTRY DATABASES
- CLASS METHODS
- OBJECT METHODS
- MAILING LISTS AND CVS
- SEE ALSO
Geo::IP - Look up country by IP Address
use Geo::IP; my $gi = Geo::IP->new(GEOIP_STANDARD); # look up IP address '18.104.22.168' # returns undef if country is unallocated, or not defined in our database my $country = $gi->country_code_by_addr('22.214.171.124'); $country = $gi->country_code_by_name('yahoo.com'); # $country is equal to "US"
This module uses a file based database. This database simply contains IP blocks as keys, and countries as values. This database should be more complete and accurate than reverse DNS lookups.
This module can be used to automatically select the geographically closest mirror, to analyze your web server logs to determine the countries of your visiters, for credit card fraud detection, and for software export controls.
IP ADDRESS TO COUNTRY DATABASES
Free monthly updates to the database are available from
This free database is similar to the database contained in IP::Country, as well as many paid databases. It uses ARIN, RIPE, APNIC, and LACNIC whois to obtain the IP->Country mappings.
If you require greater accuracy, MaxMind offers a database on a paid subscription basis. Also included with this is a service that updates your database automatically each month, by running a program called geoipupdate included with the C API from a cronjob. For more details on the differences between the free and paid databases, see: http://www.maxmind.com/app/geoip_country
- $gi = Geo::IP->new( $flags );
Constructs a new Geo::IP object with the default database located inside your system's datadir, typically /usr/local/share/GeoIP/GeoIP.dat.
Flags can be set to either GEOIP_STANDARD, or for faster performance (at a cost of using more memory), GEOIP_MEMORY_CACHE. When using memory cache you can force a reload if the file is updated by setting GEOIP_CHECK_CACHE. GEOIP_INDEX_CACHE caches the most frequently accessed index portion of the database, resulting in faster lookups than GEOIP_STANDARD, but less memory usage than GEOIP_MEMORY_CACHE - useful for larger databases such as GeoIP Organization and GeoIP City. Note, for GeoIP Country, Region and Netspeed databases, GEOIP_INDEX_CACHE is equivalent to GEOIP_MEMORY_CACHE
To combine flags, use the bitwise OR operator, |. For example, to cache the database in memory, but check for an updated GeoIP.dat file, use: Geo::IP->new( GEOIP_MEMORY_CACHE | GEOIP_CHECK_CACHE. );
- $gi = Geo::IP->open( $database_filename, $flags );
Constructs a new Geo::IP object with the database located at
- $gi = Geo::IP->open_type( $database_type, $flags );
Constructs a new Geo::IP object with the $database_type database located in the standard location. For example
$gi = Geo::IP->open_type( GEOIP_CITY_EDITION_REV1 , GEOIP_STANDARD );
opens the database file in the standard location for GeoIP City, typically /usr/local/share/GeoIP/GeoIPCity.dat.
- $code = $gi->country_code_by_addr( $ipaddr );
Returns the ISO 3166 country code for an IP address.
- $code = $gi->country_code_by_name( $hostname );
Returns the ISO 3166 country code for a hostname.
- $code = $gi->country_code3_by_addr( $ipaddr );
Returns the 3 letter country code for an IP address.
- $code = $gi->country_code3_by_name( $hostname );
Returns the 3 letter country code for a hostname.
- $name = $gi->country_name_by_addr( $ipaddr );
Returns the full country name for an IP address.
- $name = $gi->country_name_by_name( $hostname );
Returns the full country name for a hostname.
- $r = $gi->record_by_addr( $ipaddr );
Returns a Geo::IP::Record object containing city location for an IP address.
- $r = $gi->record_by_name( $hostname );
Returns a Geo::IP::Record object containing city location for a hostname.
- $org = $gi->org_by_addr( $ipaddr );
Returns the Organization or ISP name for an IP address.
- $org = $gi->org_by_name( $hostname );
Returns the Organization or ISP name for a hostname.
- $info = $gi->database_info;
Returns database string, includes version, date, build number and copyright notice.
- $old_charset = $gi->set_charset( $charset );
Set the charset for the city name - defaults to GEOIP_CHARSET_ISO_8859_1. To set UTF8, pass GEOIP_CHARSET_UTF8 to set_charset.
- $charset = $gi->charset;
Gets the currently used charset.
- $netmask = $gi->last_netmask;
Gets netmask of network block from last lookup.
MAILING LISTS AND CVS
Are available from SourceForge, see http://sourceforge.net/projects/geoip/
The direct link to the mailing list is http://lists.sourceforge.net/lists/listinfo/geoip-perl
Copyright (c) 2007, MaxMind LLC
All rights reserved. This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself.