【发布时间】:2015-03-30 19:15:44
【问题描述】:
如何在 Perl 中从 IP 地址获取国家/地区?我必须使用 whois 来做到这一点。 我知道,我可以使用国家/地区:
$test = `whois $ip |grep -i country`;
但它返回给我"Country: DE"。我只需要“DE”。
【问题讨论】:
-
您看到的国家不一定是“来自 IP 地址的国家”。您应该改为查看 search.cpan.org/~maxmind/Geo-IP-1.45/lib/Geo/IP.pm 之类的内容。
-
但我必须使用 whois :P 在学校我的任务是使用“whois”并从中获取国家/地区。
-
不要逃到 shell 去这样做,Perl 中有很多 whois 库。