全部博文(1144)
分类: LINUX
2009-12-09 13:17:22
Requirements
For Geo::IP, must be installed. Geo::IP::PurePerl is also available, which doesn't require the C Library and contains no XS code.
Download
(faster, but requires C library)
(slower, but does not require C library)
Note: there have been reports of the Geo::IP 1.25 not working on FreeBSD, please try using Geo::IP 1.24 instead on FreeBSD.
Installing on Linux
This should work on most UNIX and GNU/Linux platforms.
perl Makefile.PL make make test make install |
Installing on Windows
There is a PPM module available from Randy Kobes' PPM repository.
For ActivePerl 6xx builds, use:
C:\> ppm install |
ppm> install Geo-IP |
C:\> ppm install |
58 |
ppm> install Geo-IP |
Note there have been bug reports with using the GeoIP Perl API PPM. If you run into issues running the PPM on Windows, you may want to try the Geo::IP::PurePerl Module, which should run more reliably on Windows [].
Usage
Gets country name by hostname:
use Geo::IP; my $gi = Geo::IP->new(GEOIP_STANDARD); print $gi->country_name_by_name("amazon.com"); |
my $gi = Geo::IP->open("/usr/local/share/GeoIP/GeoIPRegion.dat", GEOIP_STANDARD); my ($country, $region) = $gi->region_by_name("24.24.24.24"); |
my $gi = Geo::IP->open("/usr/local/share/GeoIP/GeoIPCity.dat", GEOIP_STANDARD); my $r = $gi->record_by_name("24.24.24.24"); print $record->country_code, $record->country_code3, $record->country_name, $record->region, $record->region_name, $record->city, $record->postal_code, $record->latitude, $record->longitude; |