|
@@ -29,24 +29,29 @@ public class AddressUtil {
|
|
|
public static String getRealAddressByIp(String ip) {
|
|
public static String getRealAddressByIp(String ip) {
|
|
|
String address = UNKNOWN;
|
|
String address = UNKNOWN;
|
|
|
// 内网不查询
|
|
// 内网不查询
|
|
|
- if (NetUtil.isInnerIP(ip)) {
|
|
|
|
|
- return "内网IP";
|
|
|
|
|
- }
|
|
|
|
|
- if (AppConfig.isAddressEnabled()) {
|
|
|
|
|
- try {
|
|
|
|
|
- String rspStr = HttpUtil.get(IP_URL + "?ip=" + ip + "&json=true", CharsetUtil.CHARSET_GBK);
|
|
|
|
|
- if (CharSequenceUtil.isEmpty(rspStr)) {
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (NetUtil.isInnerIP(ip)) {
|
|
|
|
|
+ return "内网IP";
|
|
|
|
|
+ }
|
|
|
|
|
+ if (AppConfig.isAddressEnabled()) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ String rspStr = HttpUtil.get(IP_URL + "?ip=" + ip + "&json=true", CharsetUtil.CHARSET_GBK);
|
|
|
|
|
+ if (CharSequenceUtil.isEmpty(rspStr)) {
|
|
|
|
|
+ log.error("获取地理位置异常 {}", ip);
|
|
|
|
|
+ return UNKNOWN;
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONObject obj = JSONUtil.parseObj(rspStr);
|
|
|
|
|
+ String region = obj.getStr("pro");
|
|
|
|
|
+ String city = obj.getStr("city");
|
|
|
|
|
+ return String.format("%s %s", region, city);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
log.error("获取地理位置异常 {}", ip);
|
|
log.error("获取地理位置异常 {}", ip);
|
|
|
- return UNKNOWN;
|
|
|
|
|
}
|
|
}
|
|
|
- JSONObject obj = JSONUtil.parseObj(rspStr);
|
|
|
|
|
- String region = obj.getStr("pro");
|
|
|
|
|
- String city = obj.getStr("city");
|
|
|
|
|
- return String.format("%s %s", region, city);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("获取地理位置异常 {}", ip);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ return address;
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ return UNKNOWN;
|
|
|
}
|
|
}
|
|
|
- return address;
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|