1.fix internal ip unproper display

main
Gary 9 months ago
parent f140b04918
commit a7afa26247

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

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

@ -13,6 +13,9 @@ public class IpUtilTest {
String ip2="38.103.161.182";
System.out.println(IpUtil.getIpLocation(ip2));
String ip3="192.168.3.0";
System.out.println(IpUtil.getIpLocation(ip3));
}
}

Loading…
Cancel
Save