ドメイン名、ホスト名、IPアドレスから国名を調べる方法

GeoIPを使えばできる。

  • インストール方法
CentOS
# yum -y install GeoIP-devel GeoIP-data

Ubuntu
$ sudo apt-get install geoip-bin

perlからも使いたい場合は以下も。

# perl -MCPAN -e "install Geo::IP"
  • 使い方
# geoiplookup www.yahoo.com
GeoIP Country Edition: US, United States

# perl -MGeo::IP -e 'print Geo::IP->new(GEOIP_STANDARD)->country_code_by_addr("123.123.123.123");'
CN
# perl -MGeo::IP -e 'print Geo::IP->new(GEOIP_STANDARD)->country_code_by_name("rukatan.com");'
JP