fix: linux信息
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
package org.wfc.common.license.license;
|
||||
|
||||
import org.wfc.common.license.domain.LicenseCheckModel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.wfc.common.license.domain.LicenseCheckModel;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -74,19 +73,21 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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 inetAddress = InetAddress.getByName("host.docker.internal");
|
||||
result.add(inetAddress);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -119,4 +120,26 @@ public abstract class AbstractServerInfos {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>获取服务器信息</p>
|
||||
*
|
||||
* @param osName 系统类型
|
||||
* @return AGxServerInfos 服务信息
|
||||
*/
|
||||
public static AbstractServerInfos getServer(String osName) {
|
||||
if ("".equals(osName) || osName == null) {
|
||||
osName = System.getProperty("os.name").toLowerCase();
|
||||
}
|
||||
AbstractServerInfos abstractServerInfos;
|
||||
// 根据不同操作系统类型选择不同的数据获取方法
|
||||
if (osName.startsWith("windows")) {
|
||||
abstractServerInfos = new WindowsServerInfos();
|
||||
} else if (osName.startsWith("linux")) {
|
||||
abstractServerInfos = new LinuxServerInfos();
|
||||
} else {// 其他服务器类型
|
||||
abstractServerInfos = new LinuxServerInfos();
|
||||
}
|
||||
return abstractServerInfos;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user