Commit ec36cc0e by 周海峰

获取本地ip优化

parent 5ab19c3a
......@@ -158,29 +158,53 @@ public class LicenseKeyTool {
}
}
public static List getLinuxLocalUUID() {
List<String> ipList = new ArrayList();
String device = "";
try {
Process process = Runtime.getRuntime().exec("blkid " + device);
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while((line = reader.readLine()) != null) {
String[] ac = line.split(" ");
String uuid = ac[1];
String[] uuids = uuid.split("\"");
String uuidr = uuids[1];
ipList.add(uuidr);
public static List<String> getLinuxLocalUUID() {
List<String> resultList = new ArrayList<>();
String os = System.getProperty("os.name").toLowerCase();
System.out.println("os.name:" + os);
if (os.contains("mac")) {
// macOS 获取本地IP
try {
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
NetworkInterface ni = interfaces.nextElement();
if (!ni.getName().contains("lo") && !ni.getName().contains("docker")) {
Enumeration<InetAddress> addresses = ni.getInetAddresses();
while (addresses.hasMoreElements()) {
InetAddress addr = addresses.nextElement();
if (!addr.isLoopbackAddress() && addr instanceof java.net.Inet4Address) {
resultList.add(addr.getHostAddress());
}
}
}
}
} catch (SocketException e) {
Log.info("获取mac本地IP失败: " + e.getMessage());
}
} else {
// Linux 获取UUID
String device = "";
try {
Process process = Runtime.getRuntime().exec("blkid " + device);
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
String[] ac = line.split(" ");
if (ac.length > 1) {
String uuid = ac[1];
String[] uuids = uuid.split("\"");
if (uuids.length > 1) {
String uuidr = uuids[1];
resultList.add(uuidr);
}
}
}
reader.close();
} catch (IOException e) {
Log.info("校验的证书是不是失效--linuxLocalUUID" + e.getMessage());
}
reader.close();
} catch (IOException e) {
Log.info("校验的证书是不是失效--linuxLocalUUID" + e.getMessage());
}
return ipList;
return resultList;
}
public static List getLinuxLocalIp() throws SocketException {
......@@ -240,7 +264,8 @@ public class LicenseKeyTool {
}
public static void main(String[] args) {
String content = "有效期1个月,10.10.200.24,fe:fc:fe:21:01:2d,2024-12-11,2025-01-11,5";
// String content = "有效期1个月,10.10.200.24,fe:fc:fe:21:01:2d,2024-12-11,2025-01-11,5";
String content = "有效期1个月,172.16.100.75,3a:8f:fa:94:67:1a,2024-12-11,2025-11-11,100";
String password = "ghca";
System.out.println("加密之前:" + content);
String encrypt = AesTool.encrypt(content, password);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论