Commit 5b37b243 by 周海峰

no message

parent ec36cc0e
...@@ -18,15 +18,8 @@ import java.net.SocketException; ...@@ -18,15 +18,8 @@ import java.net.SocketException;
import java.sql.SQLException; import java.sql.SQLException;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.*;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.collections.map.HashedMap; import org.apache.commons.collections.map.HashedMap;
public class LicenseKeyTool { public class LicenseKeyTool {
...@@ -100,22 +93,13 @@ public class LicenseKeyTool { ...@@ -100,22 +93,13 @@ public class LicenseKeyTool {
map.put("endDatelicensekey", endDatelicensekey); map.put("endDatelicensekey", endDatelicensekey);
map.put("projectNum", projectNum); map.put("projectNum", projectNum);
Log.info("校验的证书是不是失效--UUID"); Log.info("校验的证书是不是失效--UUID");
List linuxLocalUUID = getLinuxLocalUUID(); List<String> linuxLocalUUID = getLinuxLocalUUID();
String mac = getLocalMacLiunx(); String mac = getLocalMacLiunx();
boolean b = false; boolean b = false;
Log.info("校验的证书是不是失效--linuxLocalUUID" + linuxLocalUUID); Log.info("校验的证书是不是失效--linuxLocalUUID" + linuxLocalUUID);
boolean matchMac = Arrays.stream(mac.split(",")).anyMatch(licInfoMac::equalsIgnoreCase);
for(int i = 0; i < linuxLocalUUID.size(); ++i) { boolean matchIp = linuxLocalUUID.stream().anyMatch(licUUid::equalsIgnoreCase);
String localUUid = (String)linuxLocalUUID.get(i); b = matchMac && matchIp;
System.out.println(localUUid + "==" + licUUid);
Log.info(localUUid + "==" + licUUid);
if (licUUid.equalsIgnoreCase(localUUid) && licInfoMac.equalsIgnoreCase(mac)) {
Log.info("成功");
b = true;
break;
}
}
if (!b) { if (!b) {
resultVO.setMessage("uuid有误"); resultVO.setMessage("uuid有误");
resultVO.setResult(false); resultVO.setResult(false);
...@@ -158,6 +142,10 @@ public class LicenseKeyTool { ...@@ -158,6 +142,10 @@ public class LicenseKeyTool {
} }
} }
/**
* 获取本机器的ip地址
* @return list
*/
public static List<String> getLinuxLocalUUID() { public static List<String> getLinuxLocalUUID() {
List<String> resultList = new ArrayList<>(); List<String> resultList = new ArrayList<>();
String os = System.getProperty("os.name").toLowerCase(); String os = System.getProperty("os.name").toLowerCase();
...@@ -201,76 +189,85 @@ public class LicenseKeyTool { ...@@ -201,76 +189,85 @@ public class LicenseKeyTool {
} }
reader.close(); reader.close();
} catch (IOException e) { } catch (IOException e) {
Log.info("校验的证书是不是失效--linuxLocalUUID" + e.getMessage()); Log.info("Linux获取ip" + e.getMessage());
} }
} }
return resultList; return resultList;
} }
public static List getLinuxLocalIp() throws SocketException { /**
List<String> ipList = new ArrayList(); * 获取本机MAC地址
String ip = ""; * @return list
* @throws SocketException
try { */
Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
while(en.hasMoreElements()) {
NetworkInterface intf = (NetworkInterface)en.nextElement();
String name = intf.getName();
if (!name.contains("docker") && !name.contains("lo")) {
Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses();
while(enumIpAddr.hasMoreElements()) {
InetAddress inetAddress = (InetAddress)enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
String ipaddress = inetAddress.getHostAddress().toString();
if (!ipaddress.contains("::") && !ipaddress.contains("0:0:") && !ipaddress.contains("fe80")) {
ipList.add(ipaddress);
}
}
}
}
}
} catch (SocketException ex) {
ip = "127.0.0.1";
ex.printStackTrace();
}
return ipList;
}
public static String getLocalMacLiunx() throws SocketException { public static String getLocalMacLiunx() throws SocketException {
String mac = ""; String mac = "";
Set<String> macSet = new HashSet<>();
try { try {
Process p = (new ProcessBuilder(new String[]{"ifconfig"})).start(); Enumeration<NetworkInterface> networks = NetworkInterface.getNetworkInterfaces();
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); while (networks.hasMoreElements()) {
NetworkInterface network = networks.nextElement();
String line; if (!network.isLoopback() && network.getHardwareAddress() != null) {
while((line = br.readLine()) != null) { byte[] macBytes = network.getHardwareAddress();
Pattern pat = Pattern.compile("\\b\\w+:\\w+:\\w+:\\w+:\\w+:\\w+\\b"); StringBuilder sb = new StringBuilder();
Matcher mat = pat.matcher(line); for (int i = 0; i < macBytes.length; i++) {
if (mat.find()) { sb.append(String.format("%02x", macBytes[i]));
mac = mat.group(0); if (i < macBytes.length - 1) {
sb.append(":");
} }
} }
System.out.println("["+sb.toString()+"]");
br.close(); macSet.add(sb.toString());
} catch (IOException var6) {
} }
}
} catch (SocketException e) {
System.out.println("获取MAC地址失败: " + e.getMessage());
}
mac = String.join(",", macSet);
System.out.println("本机MAC地址为:\n" + mac); System.out.println("本机MAC地址为:\n" + mac);
return mac; return mac;
} }
// public static String getLocalMacLiunx() throws SocketException {
// String mac = "";
//
// try {
// Process p = (new ProcessBuilder(new String[]{"ifconfig"})).start();
// BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
//
// String line;
// while((line = br.readLine()) != null) {
// Pattern pat = Pattern.compile("\\b\\w+:\\w+:\\w+:\\w+:\\w+:\\w+\\b");
// Matcher mat = pat.matcher(line);
// if (mat.find()) {
// mac = mat.group(0);
// }
// }
//
// br.close();
// } catch (IOException var6) {
// }
//
// System.out.println("本机MAC地址为:\n" + mac);
// return mac;
// }
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 content = "有效期12个月,172.16.100.75,bc:d0:74:a5:4d:b7,2024-12-11,2025-12-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);
System.out.println("加密后的内容:" + encrypt); System.out.println("加密后的内容:" + encrypt);
String decrypt = AesTool.decrypt(encrypt, password); String decrypt = AesTool.decrypt(encrypt, password);
System.out.println("解密后的内容:" + new String(decrypt)); System.out.println("解密后的内容:" + new String(decrypt));
// List<String> linuxLocalUUID = getLinuxLocalUUID();
// System.out.println(linuxLocalUUID);
// try {
// String localMacLiunx = getLocalMacLiunx();
// System.out.println(localMacLiunx);
// } catch (SocketException e) {
// throw new RuntimeException(e);
// }
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论