fix: linux信息

This commit is contained in:
caiyuchao
2025-04-17 18:03:38 +08:00
parent 9cf8afbbcc
commit 4eaf622c28
2 changed files with 15 additions and 18 deletions

View File

@@ -7,6 +7,7 @@ import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
/**
@@ -73,22 +74,18 @@ public abstract class AbstractServerInfos {
List<InetAddress> result = new ArrayList<>(4);
// 遍历所有的网络接口
// for (Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces(); networkInterfaces.hasMoreElements(); ) {
// NetworkInterface iface = (NetworkInterface) networkInterfaces.nextElement();
// // 在所有的接口下再遍历IP
// for (Enumeration inetAddresses = iface.getInetAddresses(); inetAddresses.hasMoreElements(); ) {
// InetAddress inetAddr = (InetAddress) inetAddresses.nextElement();
//
// //排除LoopbackAddress、SiteLocalAddress、LinkLocalAddress、MulticastAddress类型的IP地址
// if (!inetAddr.isLoopbackAddress() /*&& !inetAddr.isSiteLocalAddress()*/
// && !inetAddr.isLinkLocalAddress() && !inetAddr.isMulticastAddress()) {
// result.add(inetAddr);
// }
// }
// }
InetAddress[] inetAddressArr = InetAddress.getAllByName("host.docker.internal");
for (InetAddress inetAddress : inetAddressArr) {
result.add(inetAddress);
for (Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces(); networkInterfaces.hasMoreElements(); ) {
NetworkInterface iface = (NetworkInterface) networkInterfaces.nextElement();
// 在所有的接口下再遍历IP
for (Enumeration inetAddresses = iface.getInetAddresses(); inetAddresses.hasMoreElements(); ) {
InetAddress inetAddr = (InetAddress) inetAddresses.nextElement();
//排除LoopbackAddress、SiteLocalAddress、LinkLocalAddress、MulticastAddress类型的IP地址
if (!inetAddr.isLoopbackAddress() /*&& !inetAddr.isSiteLocalAddress()*/
&& !inetAddr.isLinkLocalAddress() && !inetAddr.isMulticastAddress()) {
result.add(inetAddr);
}
}
}
return result;
}

View File

@@ -48,7 +48,7 @@ public class LinuxServerInfos extends AbstractServerInfos {
String serialNumber = "";
//使用dmidecode命令获取CPU序列号
String[] shell = {"/bin/bash", "-c", "sudo dmidecode -t processor | grep 'ID' | awk -F ':' '{print $2}' | head -n 1"};
String[] shell = {"/bin/bash", "-c", "dmidecode -t processor | grep 'ID' | awk -F ':' '{print $2}' | head -n 1"};
Process process = Runtime.getRuntime().exec(shell);
process.getOutputStream().close();
@@ -69,7 +69,7 @@ public class LinuxServerInfos extends AbstractServerInfos {
String serialNumber = "";
//使用dmidecode命令获取主板序列号
String[] shell = {"/bin/bash", "-c", "sudo dmidecode | grep 'Serial Number' | awk -F ':' '{print $2}' | head -n 1"};
String[] shell = {"/bin/bash", "-c", "dmidecode | grep 'Serial Number' | awk -F ':' '{print $2}' | head -n 1"};
Process process = Runtime.getRuntime().exec(shell);
process.getOutputStream().close();