From a7afa262472a94a0abc5ab38a158b0e2f181cbe0 Mon Sep 17 00:00:00 2001 From: Gary Date: Sun, 10 Mar 2024 08:35:57 +0800 Subject: [PATCH] 1.fix internal ip unproper display --- luoo_comment/src/main/java/com/luoo/comment/util/IpUtil.java | 4 ++++ luoo_user/src/main/java/com/luoo/user/util/IpUtil.java | 4 ++++ luoo_user/src/test/java/com/luoo/user/util/IpUtilTest.java | 3 +++ 3 files changed, 11 insertions(+) diff --git a/luoo_comment/src/main/java/com/luoo/comment/util/IpUtil.java b/luoo_comment/src/main/java/com/luoo/comment/util/IpUtil.java index 0b74f28..529fda5 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/util/IpUtil.java +++ b/luoo_comment/src/main/java/com/luoo/comment/util/IpUtil.java @@ -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; diff --git a/luoo_user/src/main/java/com/luoo/user/util/IpUtil.java b/luoo_user/src/main/java/com/luoo/user/util/IpUtil.java index c068927..9a1e793 100644 --- a/luoo_user/src/main/java/com/luoo/user/util/IpUtil.java +++ b/luoo_user/src/main/java/com/luoo/user/util/IpUtil.java @@ -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; diff --git a/luoo_user/src/test/java/com/luoo/user/util/IpUtilTest.java b/luoo_user/src/test/java/com/luoo/user/util/IpUtilTest.java index bef2322..fa9ddb9 100644 --- a/luoo_user/src/test/java/com/luoo/user/util/IpUtilTest.java +++ b/luoo_user/src/test/java/com/luoo/user/util/IpUtilTest.java @@ -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)); } }