// 引用hutool的httpUtil和阿里的json依赖
public static String getAddress(String ip) {
try {
String result = HttpUtil.get("http://whois.pconline.com.cn/ipJson.jsp?ip=" + ip + "&json=true");
JSONObject jsonObject = JSONObject.parseObject(result);
if (jsonObject != null && StringUtils.isNotEmpty(jsonObject.getString("addr"))) {
return jsonObject.getString("addr");
}
return null;
} catch (Exception e) {
e.printStackTrace();
log.info("IP地址信息解析异常--->{}",e.getMessage());
return null;
}
}
java 根据ip获取省市区
原创
©著作权归作者所有:来自51CTO博客作者苦力小w的原创作品,请联系作者获取转载授权,否则将追究法律责任
下一篇:linux 防火墙命令
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
java根据表名称获取所有字段
java根据表名称获取所有字段
字段 java sql -
获取ip对应的省市区
必须的必啊,先通过“ 晋阳子 / php-iplocation”,通过他能获取到地理范围,如下而我需要的
php 开发语言 ip地址 Real