Commit ec36cc0e by 周海峰

获取本地ip优化

parent 5ab19c3a
...@@ -158,29 +158,53 @@ public class LicenseKeyTool { ...@@ -158,29 +158,53 @@ public class LicenseKeyTool {
} }
} }
public static List getLinuxLocalUUID() { public static List<String> getLinuxLocalUUID() {
List<String> ipList = new ArrayList(); List<String> resultList = new ArrayList<>();
String device = ""; String os = System.getProperty("os.name").toLowerCase();
System.out.println("os.name:" + os);
try { if (os.contains("mac")) {
Process process = Runtime.getRuntime().exec("blkid " + device); // macOS 获取本地IP
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); try {
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
String line; while (interfaces.hasMoreElements()) {
while((line = reader.readLine()) != null) { NetworkInterface ni = interfaces.nextElement();
String[] ac = line.split(" "); if (!ni.getName().contains("lo") && !ni.getName().contains("docker")) {
String uuid = ac[1]; Enumeration<InetAddress> addresses = ni.getInetAddresses();
String[] uuids = uuid.split("\""); while (addresses.hasMoreElements()) {
String uuidr = uuids[1]; InetAddress addr = addresses.nextElement();
ipList.add(uuidr); 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 resultList;
return ipList;
} }
public static List getLinuxLocalIp() throws SocketException { public static List getLinuxLocalIp() throws SocketException {
...@@ -240,7 +264,8 @@ public class LicenseKeyTool { ...@@ -240,7 +264,8 @@ public class LicenseKeyTool {
} }
public static void main(String[] args) { 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"; String password = "ghca";
System.out.println("加密之前:" + content); System.out.println("加密之前:" + content);
String encrypt = AesTool.encrypt(content, password); String encrypt = AesTool.encrypt(content, password);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论