fix: linux信息
This commit is contained in:
@@ -7,6 +7,7 @@ import java.net.InetAddress;
|
|||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Enumeration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -73,22 +74,18 @@ public abstract class AbstractServerInfos {
|
|||||||
List<InetAddress> result = new ArrayList<>(4);
|
List<InetAddress> result = new ArrayList<>(4);
|
||||||
|
|
||||||
// 遍历所有的网络接口
|
// 遍历所有的网络接口
|
||||||
// for (Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces(); networkInterfaces.hasMoreElements(); ) {
|
for (Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces(); networkInterfaces.hasMoreElements(); ) {
|
||||||
// NetworkInterface iface = (NetworkInterface) networkInterfaces.nextElement();
|
NetworkInterface iface = (NetworkInterface) networkInterfaces.nextElement();
|
||||||
// // 在所有的接口下再遍历IP
|
// 在所有的接口下再遍历IP
|
||||||
// for (Enumeration inetAddresses = iface.getInetAddresses(); inetAddresses.hasMoreElements(); ) {
|
for (Enumeration inetAddresses = iface.getInetAddresses(); inetAddresses.hasMoreElements(); ) {
|
||||||
// InetAddress inetAddr = (InetAddress) inetAddresses.nextElement();
|
InetAddress inetAddr = (InetAddress) inetAddresses.nextElement();
|
||||||
//
|
|
||||||
// //排除LoopbackAddress、SiteLocalAddress、LinkLocalAddress、MulticastAddress类型的IP地址
|
//排除LoopbackAddress、SiteLocalAddress、LinkLocalAddress、MulticastAddress类型的IP地址
|
||||||
// if (!inetAddr.isLoopbackAddress() /*&& !inetAddr.isSiteLocalAddress()*/
|
if (!inetAddr.isLoopbackAddress() /*&& !inetAddr.isSiteLocalAddress()*/
|
||||||
// && !inetAddr.isLinkLocalAddress() && !inetAddr.isMulticastAddress()) {
|
&& !inetAddr.isLinkLocalAddress() && !inetAddr.isMulticastAddress()) {
|
||||||
// result.add(inetAddr);
|
result.add(inetAddr);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
InetAddress[] inetAddressArr = InetAddress.getAllByName("host.docker.internal");
|
|
||||||
for (InetAddress inetAddress : inetAddressArr) {
|
|
||||||
result.add(inetAddress);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public class LinuxServerInfos extends AbstractServerInfos {
|
|||||||
String serialNumber = "";
|
String serialNumber = "";
|
||||||
|
|
||||||
//使用dmidecode命令获取CPU序列号
|
//使用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 process = Runtime.getRuntime().exec(shell);
|
||||||
process.getOutputStream().close();
|
process.getOutputStream().close();
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ public class LinuxServerInfos extends AbstractServerInfos {
|
|||||||
String serialNumber = "";
|
String serialNumber = "";
|
||||||
|
|
||||||
//使用dmidecode命令获取主板序列号
|
//使用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 process = Runtime.getRuntime().exec(shell);
|
||||||
process.getOutputStream().close();
|
process.getOutputStream().close();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user