|
Apache2::Geo::IP - Look up country by IP address |
Apache2::Geo::IP - Look up country by IP address
# in httpd.conf # PerlModule Apache2::HelloIP #<Location /ip> # SetHandler perl-script # PerlResponseHandler Apache2::HelloIP # PerlSetVar GeoIPDBFile "/usr/local/share/GeoIP/GeoIP.dat" # PerlSetVar GeoIPFlag Standard #</Location>
# file Apache2::HelloIP
use Apache2::Geo::IP; use strict;
use Apache2::Const -compile => 'OK';
sub handler {
my $r = Apache2::Geo::IP->new(shift);
$r->content_type('text/plain');
my $country = uc($r->country_code_by_addr());
$r->print($country);
return Apache2::OK; } 1;
=head1 DESCRIPTION
This module constitutes a mod_perl (version 2) interface to the Geo::IP module, which looks up in a database a country of origin of an IP address. 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.
If you are on Win32 and have installed this package using the ActivePerl ppm utility, the database GeoIP.dat is expected to be found under the C:\Program Files\GeoIP\ directory.
To find a country for an IP address, this module a finds the Network that contains the IP address, then returns the country the Network is assigned to.
This module subclasses Apache2::RequestRec, and can be used as follows in an Apache module.
# file Apache2::HelloIP
use Apache2::Geo::IP; use strict;
sub handler {
my $r = Apache2::Geo::IP->new(shift);
# continue along
}
The directives in F<httpd.conf> are as follows:
<Location /ip>
PerlSetVar GeoIPDBFile "/usr/local/share/GeoIP/GeoIP.dat"
PerlSetVar GeoIPFlag Standard
# other directives
</Location>
The C<PerlSetVar> directives available are
The available methods are as follows.
$r->connection->remote_ip is used.
$r->get_remote_host(Apache2::Const::REMOTE_HOST) is used.
$r->connection->remote_ip is used.
$r->get_remote_host(Apache2::Const::REMOTE_HOST) is used.
$r->connection->remote_ip is used.
$r->get_remote_host(Apache2::Const::REMOTE_HOST) is used.
the Geo::IP manpage and the Apache2::RequestRec manpage.
The look-up code for associating a country with an IP address is based on the GeoIP library and the Geo::IP Perl module, and is Copyright (c) 2002, T.J. Mather, tjmather@tjmather.com, New York, NY, USA. See http://www.maxmind.com/ for details. The mod_perl interface is Copyright (c) 2002, Randy Kobes <randy@theoryx5.uwinnipeg.ca>.
All rights reserved. This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|
Apache2::Geo::IP - Look up country by IP address |