Apache::Geo::IP - Look up country by IP Address |
Apache::Geo::IP - Look up country by IP Address
# in httpd.conf # PerlModule Apache::HelloIP #<Location /ip> # SetHandler perl-script # PerlHandler Apache::HelloIP # PerlSetVar GeoIPDBFile "/usr/local/share/GeoIP/GeoIP.dat" # PerlSetVar GeoIPFlag Standard #</Location> # file Apache::HelloIP use Apache::Geo::IP; use strict; use Apache::Constants qw(OK); sub handler { my $r = Apache::Geo::IP->new(shift); $r->content_type('text/plain'); my $country = uc($r->country_code_by_addr()); $r->print($country); return OK; } 1;
This module constitutes a mod_perl (version 1) 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.
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 Apache, and can be used as follows in an Apache module.
# file Apache::HelloIP
use Apache::Geo::IP; use strict;
sub handler { my $r = Apache::Geo::IP->new(shift); # continue along }
The directives in F<httpd.conf> are as follows:
PerlModule Apache::HelloIP <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(REMOTE_HOST)
is used.
$r->connection->remote_ip
is used.
$r->get_remote_host(REMOTE_HOST)
is used.
$r->connection->remote_ip
is used.
$r->get_remote_host(REMOTE_HOST)
is used.
1.11
the Geo::IP manpage and Apache.
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.
Apache::Geo::IP - Look up country by IP Address |