From 8e0ee72036dadf56a80d2036f3df5c1a8e869f72 Mon Sep 17 00:00:00 2001 From: chenzhangyue <15696756582@163.com> Date: Sat, 25 Nov 2023 13:33:00 +0800 Subject: [PATCH 1/2] =?UTF-8?q?:bookmark:=202.5.2=20ip=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/luna/common/os/SystemInfoUtil.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/luna/common/os/SystemInfoUtil.java b/src/main/java/com/luna/common/os/SystemInfoUtil.java index a1081858..74f03c4a 100644 --- a/src/main/java/com/luna/common/os/SystemInfoUtil.java +++ b/src/main/java/com/luna/common/os/SystemInfoUtil.java @@ -7,11 +7,12 @@ import java.util.*; import java.util.stream.Collectors; -import com.google.common.collect.Lists; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.RandomUtils; - import org.apache.commons.lang3.StringUtils; -import org.checkerframework.checker.nullness.qual.Nullable; + +import com.google.common.collect.Lists; + import oshi.SystemInfo; import oshi.software.os.OSProcess; @@ -55,11 +56,27 @@ public static String getIP() { return getLocalHost().getHostAddress(); } + public static String getIpv4() { + return Objects.requireNonNull(getAllIpv4()).stream().findFirst().orElse(null); + } + /** * 本级ip 过滤 回环地址、链路本地地址或多播地址 * * @return */ + public static List getAllIpv4() { + List allIpAddress = getAllIpAddress(); + if (CollectionUtils.isEmpty(allIpAddress)) { + return new ArrayList<>(); + } + return allIpAddress.stream().filter(e -> !e.contains(":")).collect(Collectors.toList()); + } + + /** + * 本级ip 过滤 回环地址、链路本地地址或多播地址 + * @return + */ public static String getNoLoopbackIP() { return getAddress().getHostAddress(); } @@ -74,7 +91,6 @@ public static List getAllIpAddress() { /** * 获取非回环网卡IP - * * @return */ public static InetAddress getAddress() { From a7e2a957b235078697ba797bb369e72548646db5 Mon Sep 17 00:00:00 2001 From: chenzhangyue <15696756582@163.com> Date: Tue, 28 Nov 2023 15:25:59 +0800 Subject: [PATCH 2/2] :bookmark: 2.5.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4e4b84ad..b84e2240 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ io.github.lunasaw luna-common luna-common - 2.5.1 + 2.5.2 common is project which contains common utils https://github.com/lunasaw/luna-common