Skip to content

Commit

Permalink
Merge pull request #18 from lunasaw/dev_2.5.2
Browse files Browse the repository at this point in the history
Dev 2.5.2
  • Loading branch information
lunasaw authored Nov 28, 2023
2 parents 93da57e + a7e2a95 commit a2337fa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>io.github.lunasaw</groupId>
<artifactId>luna-common</artifactId>
<name>luna-common</name>
<version>2.5.1</version>
<version>2.5.2</version>
<description>common is project which contains common utils</description>
<url>https://github.com/lunasaw/luna-common</url>

Expand Down
24 changes: 20 additions & 4 deletions src/main/java/com/luna/common/os/SystemInfoUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<String> getAllIpv4() {
List<String> 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();
}
Expand All @@ -74,7 +91,6 @@ public static List<String> getAllIpAddress() {

/**
* 获取非回环网卡IP
*
* @return
*/
public static InetAddress getAddress() {
Expand Down

0 comments on commit a2337fa

Please sign in to comment.