Skip to content

Instantly share code, notes, and snippets.

@ywindish
Created June 15, 2016 09:05
Show Gist options
  • Save ywindish/04a46f9b17d1f1b54b6a324f228b0fc7 to your computer and use it in GitHub Desktop.
Save ywindish/04a46f9b17d1f1b54b6a324f228b0fc7 to your computer and use it in GitHub Desktop.
GeoIPをつかってIPアドレスから国コードを引く
#!/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";
@ywindish
Copy link
Author

国コードから国名を引くにはここを見よう
https://ja.wikipedia.org/wiki/ISO_3166-1

@ywindish
Copy link
Author

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