Created
June 15, 2016 09:05
-
-
Save ywindish/04a46f9b17d1f1b54b6a324f228b0fc7 to your computer and use it in GitHub Desktop.
GeoIPをつかってIPアドレスから国コードを引く
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Geo::IP; | |
my $ipaddr = $ARGV[0] || die "usage: geoip.pl <ip_addr>"; | |
my $gi = Geo::IP->open("/usr/local/share/GeoIP/GeoIP.dat", GEOIP_STANDARD); | |
my $country = $gi->country_code_by_addr($ipaddr); | |
print $ipaddr." 's country is ".$country."\n"; |
wget -N http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
gunzip -f GeoIP.dat.gz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
国コードから国名を引くにはここを見よう
https://ja.wikipedia.org/wiki/ISO_3166-1