You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.6 KiB
61 lines
1.6 KiB
package com.archive.common.utils;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.archive.common.utils.IpUtils;
|
|
import com.archive.common.utils.StringUtils;
|
|
import com.archive.common.utils.http.HttpUtils;
|
|
import com.archive.framework.config.ArchiveConfig;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
|
|
public class AddressUtils
|
|
{
|
|
private static final Logger log = LoggerFactory.getLogger(com.archive.common.utils.AddressUtils.class);
|
|
|
|
|
|
public static final String IP_URL = "http://whois.pconline.com.cn/ipJson.jsp";
|
|
|
|
|
|
public static final String UNKNOWN = "XX XX";
|
|
|
|
|
|
public static String getRealAddressByIP(String ip) {
|
|
String address = "XX XX";
|
|
|
|
if (IpUtils.internalIp(ip))
|
|
{
|
|
return "内网IP";
|
|
}
|
|
if (ArchiveConfig.isAddressEnabled()) {
|
|
|
|
try {
|
|
|
|
String rspStr = HttpUtils.sendGet("http://whois.pconline.com.cn/ipJson.jsp", "ip=" + ip + "&json=true", "GBK");
|
|
if (StringUtils.isEmpty(rspStr)) {
|
|
|
|
log.error("获取地理位置异常 {}", ip);
|
|
return "XX XX";
|
|
}
|
|
JSONObject obj = JSONObject.parseObject(rspStr);
|
|
String region = obj.getString("pro");
|
|
String city = obj.getString("city");
|
|
return String.format("%s %s", new Object[] { region, city });
|
|
}
|
|
catch (Exception e) {
|
|
|
|
log.error("获取地理位置异常 {}", e);
|
|
}
|
|
}
|
|
return address;
|
|
}
|
|
}
|
|
|
|
|
|
/* Location: C:\Users\Administrator\Desktop\extracted.zip!\extracted\BOOT-INF\classes\com\archive\commo\\utils\AddressUtils.class
|
|
* Java compiler version: 8 (52.0)
|
|
* JD-Core Version: 1.1.3
|
|
*/ |