fix: linux信息
This commit is contained in:
@@ -1,13 +1,12 @@
|
|||||||
package org.wfc.common.license.license;
|
package org.wfc.common.license.license;
|
||||||
|
|
||||||
import org.wfc.common.license.domain.LicenseCheckModel;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.wfc.common.license.domain.LicenseCheckModel;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,19 +73,21 @@ 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 inetAddress = InetAddress.getByName("host.docker.internal");
|
||||||
|
result.add(inetAddress);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,4 +120,26 @@ public abstract class AbstractServerInfos {
|
|||||||
}
|
}
|
||||||
return null;
|
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