[root@dr-mysql01 ~]# cat ip.pl
use Encode;
use Encode::CN;
use JSON;
use URI::Escape;
use LWP::Simple;
print "hostip is $_\n";
$host = "http://ip.taobao.com/service/getIpInfo.php?ip=$ARGV[0]";
$content = get($host);
print "$content\n";
$perl_scalar = decode_json($content);
$var=$perl_scalar->{data}->{ip};
print $var
[root@dr-mysql01 ~]# perl ip.pl 202.101.172.35
hostip is
{"code":0,"data":{"country":"\u4e2d\u56fd","country_id":"CN","area":"\u534e\u4e1c","area_id":"300000","region":"\u6d59\u6c5f\u7701","region_id":"330000","city":"\u676d\u5dde\u5e02","city_id":
perl 解析JSON
最新推荐文章于 2023-04-02 08:17:14 发布
这是一个使用Perl解析JSON来获取IP地址详细地理位置信息的脚本示例。通过调用淘宝API获取IP信息,然后使用JSON模块解码响应内容,提取出IP的国家、地区、城市等详情。
摘要由CSDN通过智能技术生成