1Geo::IP(3) User Contributed Perl Documentation Geo::IP(3)
2
3
4
6 Geo::IP - Look up location and network information by IP Address
7
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
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
26 countries of your visitors, for credit card fraud detection, and for
27 software export controls.
28
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
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
52 performance (at a cost of using more memory), GEOIP_MEMORY_CACHE.
53 When using memory cache you can force a reload if the file is
54 updated by setting GEOIP_CHECK_CACHE. GEOIP_INDEX_CACHE caches the
55 most frequently accessed index portion of the database, resulting
56 in faster lookups than GEOIP_STANDARD, but less memory usage than
57 GEOIP_MEMORY_CACHE - useful for larger databases such as GeoIP
58 Organization and GeoIP City. Note, for GeoIP Country, Region and
59 Netspeed databases, GEOIP_INDEX_CACHE is equivalent to
60 GEOIP_MEMORY_CACHE
61
62 To combine flags, use the bitwise OR operator, |. For example, to
63 cache the database in memory, but check for an updated GeoIP.dat
64 file, use: Geo::IP->new( GEOIP_MEMORY_CACHE | GEOIP_CHECK_CACHE. );
65
66 $gi = Geo::IP->open( $database_filename, $flags );
67 Constructs a new Geo::IP object with the database located at
68 $database_filename.
69
70 $gi = Geo::IP->open_type( $database_type, $flags );
71 Constructs a new Geo::IP object with the $database_type database
72 located in the standard location. For example
73
74 $gi = Geo::IP->open_type( GEOIP_CITY_EDITION_REV1 , GEOIP_STANDARD );
75
76 opens the database file in the standard location for GeoIP City,
77 typically /usr/local/share/GeoIP/GeoIPCity.dat.
78
80 $code = $gi->country_code_by_addr( $ipaddr );
81 Returns the ISO 3166 country code for an IP address.
82
83 $code = $gi->country_code_by_name( $hostname );
84 Returns the ISO 3166 country code for a hostname.
85
86 $code = $gi->country_code3_by_addr( $ipaddr );
87 Returns the 3 letter country code for an IP address.
88
89 $code = $gi->country_code3_by_name( $hostname );
90 Returns the 3 letter country code for a hostname.
91
92 $name = $gi->country_name_by_addr( $ipaddr );
93 Returns the full country name for an IP address.
94
95 $name = $gi->country_name_by_name( $hostname );
96 Returns the full country name for a hostname.
97
98 $r = $gi->record_by_addr( $ipaddr );
99 Returns a Geo::IP::Record object containing city location for an IP
100 address.
101
102 $r = $gi->record_by_name( $hostname );
103 Returns a Geo::IP::Record object containing city location for a
104 hostname.
105
106 $org = $gi->org_by_addr( $ipaddr );
107 Returns the Organization, ISP name or Domain Name for an IP
108 address.
109
110 $org = $gi->org_by_name( $hostname );
111 Returns the Organization, ISP name or Domain Name for a hostname.
112
113 $info = $gi->database_info;
114 Returns database string, includes version, date, build number and
115 copyright notice.
116
117 $old_charset = $gi->set_charset( $charset );
118 Set the charset for the city name - defaults to
119 GEOIP_CHARSET_ISO_8859_1. To set UTF8, pass GEOIP_CHARSET_UTF8 to
120 set_charset. For perl >= 5.008 the utf8 flag is honored.
121
122 $charset = $gi->charset;
123 Gets the currently used charset.
124
125 ( $country, $region ) = $gi->region_by_addr('24.24.24.24');
126 Returns a list containing country and region. If region and/or
127 country is unknown, undef is returned. Sure this works only for
128 region databases.
129
130 ( $country, $region ) = $gi->region_by_name('www.xyz.com');
131 Returns a list containing country and region. If region and/or
132 country is unknown, undef is returned. Sure this works only for
133 region databases.
134
135 $netmask = $gi->last_netmask;
136 Gets netmask of network block from last lookup.
137
138 $gi->netmask(12);
139 Sets netmask for the last lookup
140
141 my ( $from, $to ) = $gi->range_by_ip('24.24.24.24');
142 Returns the start and end of the current network block. The method
143 tries to join several continous netblocks.
144
146 Are available from SourceForge, see
147 http://sourceforge.net/projects/geoip/
148
149 The direct link to the mailing list is
150 http://lists.sourceforge.net/lists/listinfo/geoip-perl
151
153 1.38
154
156 Geo::IP::Record
157
159 Copyright (c) 2009, MaxMind, Inc
160
161 All rights reserved. This package is free software; you can
162 redistribute it and/or modify it under the same terms as Perl itself.
163
164
165
166perl v5.12.0 2009-05-17 Geo::IP(3)