1Geo::IP(3)            User Contributed Perl Documentation           Geo::IP(3)
2
3
4

NAME

6       Geo::IP - Look up location and network information by IP Address
7

SYNOPSIS

9         use Geo::IP;
10
11         my $gi = Geo::IP->new(GEOIP_STANDARD);
12
13         # look up IP address '24.24.24.24'
14         # returns undef if country is unallocated, or not defined in our database
15         my $country = $gi->country_code_by_addr('24.24.24.24');
16         $country = $gi->country_code_by_name('yahoo.com');
17         # $country is equal to "US"
18

DESCRIPTION

20       This module uses a file based database.  This database simply contains
21       IP blocks as keys, and countries as values.  This database should be
22       more complete and accurate than reverse DNS lookups.
23
24       This module can be used to automatically select the geographically
25       closest mirror, to analyze your web server logs to determine the coun‐
26       tries of your visitors, for credit card fraud detection, and for soft‐
27       ware export controls.
28

IP ADDRESS TO COUNTRY DATABASES

30       Free monthly updates to the database are available from
31
32         http://www.maxmind.com/download/geoip/database/
33
34       This free database is similar to the database contained in IP::Country,
35       as well as many paid databases. It uses ARIN, RIPE, APNIC, and LACNIC
36       whois to obtain the IP->Country mappings.
37
38       If you require greater accuracy, MaxMind offers a database on a paid
39       subscription basis.  Also included with this is a service that updates
40       your database automatically each month, by running a program called
41       geoipupdate included with the C API from a cronjob.  For more details
42       on the differences between the free and paid databases, see:
43       http://www.maxmind.com/app/geoip_country
44

CLASS METHODS

46       $gi = Geo::IP->new( $flags );
47           Constructs a new Geo::IP object with the default database located
48           inside your system's datadir, typically
49           /usr/local/share/GeoIP/GeoIP.dat.
50
51           Flags can be set to either GEOIP_STANDARD, or for faster perfor‐
52           mance (at a cost of using more memory), GEOIP_MEMORY_CACHE.  When
53           using memory cache you can force a reload if the file is updated by
54           setting GEOIP_CHECK_CACHE.  GEOIP_INDEX_CACHE caches the most fre‐
55           quently accessed index portion of the database, resulting in faster
56           lookups than GEOIP_STANDARD, but less memory usage than GEOIP_MEM‐
57           ORY_CACHE - useful for larger databases such as GeoIP Organization
58           and GeoIP City.  Note, for GeoIP Country, Region and Netspeed data‐
59           bases, GEOIP_INDEX_CACHE is equivalent to GEOIP_MEMORY_CACHE
60
61           To combine flags, use the bitwise OR operator, ⎪.  For example, to
62           cache the database in memory, but check for an updated GeoIP.dat
63           file, use: Geo::IP->new( GEOIP_MEMORY_CACHE ⎪ GEOIP_CHECK_CACHE. );
64
65       $gi = Geo::IP->open( $database_filename, $flags );
66           Constructs a new Geo::IP object with the database located at $data‐
67           base_filename.
68
69       $gi = Geo::IP->open_type( $database_type, $flags );
70           Constructs a new Geo::IP object with the $database_type database
71           located in the standard location.  For example
72
73             $gi = Geo::IP->open_type( GEOIP_CITY_EDITION_REV1 , GEOIP_STANDARD );
74
75           opens the database file in the standard location for GeoIP City,
76           typically /usr/local/share/GeoIP/GeoIPCity.dat.
77

OBJECT METHODS

79       $code = $gi->country_code_by_addr( $ipaddr );
80           Returns the ISO 3166 country code for an IP address.
81
82       $code = $gi->country_code_by_name( $hostname );
83           Returns the ISO 3166 country code for a hostname.
84
85       $code = $gi->country_code3_by_addr( $ipaddr );
86           Returns the 3 letter country code for an IP address.
87
88       $code = $gi->country_code3_by_name( $hostname );
89           Returns the 3 letter country code for a hostname.
90
91       $name = $gi->country_name_by_addr( $ipaddr );
92           Returns the full country name for an IP address.
93
94       $name = $gi->country_name_by_name( $hostname );
95           Returns the full country name for a hostname.
96
97       $r = $gi->record_by_addr( $ipaddr );
98           Returns a Geo::IP::Record object containing city location for an IP
99           address.
100
101       $r = $gi->record_by_name( $hostname );
102           Returns a Geo::IP::Record object containing city location for a
103           hostname.
104
105       $org = $gi->org_by_addr( $ipaddr );
106           Returns the Organization, ISP name or Domain Name for an IP
107           address.
108
109       $org = $gi->org_by_name( $hostname );
110           Returns the Organization, ISP name or Domain Name for a hostname.
111
112       $info = $gi->database_info;
113           Returns database string, includes version, date, build number and
114           copyright notice.
115
116       $old_charset = $gi->set_charset( $charset );
117           Set the charset for the city name - defaults to
118           GEOIP_CHARSET_ISO_8859_1.  To set UTF8, pass GEOIP_CHARSET_UTF8 to
119           set_charset.
120
121       $charset = $gi->charset;
122           Gets the currently used charset.
123
124       $netmask = $gi->last_netmask;
125           Gets netmask of network block from last lookup.
126

MAILING LISTS AND CVS

128       Are available from SourceForge, see http://source
129       forge.net/projects/geoip/
130
131       The direct link to the mailing list is http://lists.source
132       forge.net/lists/listinfo/geoip-perl
133

VERSION

135       1.31
136

SEE ALSO

138       Geo::IP::Record
139

AUTHOR

141       Copyright (c) 2008, MaxMind, Inc
142
143       All rights reserved.  This package is free software; you can redis‐
144       tribute it and/or modify it under the same terms as Perl itself.
145
146
147
148perl v5.8.8                       2004-09-20                        Geo::IP(3)
Impressum