|
|
@ -11,6 +11,7 @@ import java.io.InputStream;
|
|
|
|
public class IpUtil {
|
|
|
|
public class IpUtil {
|
|
|
|
private static final String IP2REGION_DB_FILE_PATH = "ip2region.xdb";
|
|
|
|
private static final String IP2REGION_DB_FILE_PATH = "ip2region.xdb";
|
|
|
|
private static final String UNKNOW_IP = "未知IP";
|
|
|
|
private static final String UNKNOW_IP = "未知IP";
|
|
|
|
|
|
|
|
private static final String INTERNAL_IP = "内网IP";
|
|
|
|
private static final Searcher searcher = initSearcher();
|
|
|
|
private static final Searcher searcher = initSearcher();
|
|
|
|
|
|
|
|
|
|
|
|
private static Searcher initSearcher() {
|
|
|
|
private static Searcher initSearcher() {
|
|
|
@ -29,6 +30,9 @@ public class IpUtil {
|
|
|
|
if (ipLocation.startsWith(Constants.IP_LOCATION_CHINA)) {
|
|
|
|
if (ipLocation.startsWith(Constants.IP_LOCATION_CHINA)) {
|
|
|
|
return ipLocation.split("\\|")[2].replaceFirst("省", "");
|
|
|
|
return ipLocation.split("\\|")[2].replaceFirst("省", "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ipLocation.contains(INTERNAL_IP)) {
|
|
|
|
|
|
|
|
return INTERNAL_IP;
|
|
|
|
|
|
|
|
}
|
|
|
|
return ipLocation.split("\\|")[0];
|
|
|
|
return ipLocation.split("\\|")[0];
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
return UNKNOW_IP;
|
|
|
|
return UNKNOW_IP;
|
|
|
|