Commit 5b37b243 by 周海峰

no message

parent ec36cc0e
......@@ -18,15 +18,8 @@ import java.net.SocketException;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
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 java.util.*;
import org.apache.commons.collections.map.HashedMap;
public class LicenseKeyTool {
......@@ -100,22 +93,13 @@ public class LicenseKeyTool {
map.put("endDatelicensekey", endDatelicensekey);
map.put("projectNum", projectNum);
Log.info("校验的证书是不是失效--UUID");
List linuxLocalUUID = getLinuxLocalUUID();
List<String> linuxLocalUUID = getLinuxLocalUUID();
String mac = getLocalMacLiunx();
boolean b = false;
Log.info("校验的证书是不是失效--linuxLocalUUID" + linuxLocalUUID);
for(int i = 0; i < linuxLocalUUID.size(); ++i) {
String localUUid = (String)linuxLocalUUID.get(i);
System.out.println(localUUid + "==" + licUUid);
Log.info(localUUid + "==" + licUUid);
if (licUUid.equalsIgnoreCase(localUUid) && licInfoMac.equalsIgnoreCase(mac)) {
Log.info("成功");
b = true;
break;
}
}
boolean matchMac = Arrays.stream(mac.split(",")).anyMatch(licInfoMac::equalsIgnoreCase);
boolean matchIp = linuxLocalUUID.stream().anyMatch(licUUid::equalsIgnoreCase);
b = matchMac && matchIp;
if (!b) {
resultVO.setMessage("uuid有误");
resultVO.setResult(false);
......@@ -158,6 +142,10 @@ public class LicenseKeyTool {
}
}
/**
* 获取本机器的ip地址
* @return list
*/
public static List<String> getLinuxLocalUUID() {
List<String> resultList = new ArrayList<>();
String os = System.getProperty("os.name").toLowerCase();
......@@ -201,76 +189,85 @@ public class LicenseKeyTool {
}
reader.close();
} catch (IOException e) {
Log.info("校验的证书是不是失效--linuxLocalUUID" + e.getMessage());
Log.info("Linux获取ip" + e.getMessage());
}
}
return resultList;
}
public static List getLinuxLocalIp() throws SocketException {
List<String> ipList = new ArrayList();
String ip = "";
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;
}
/**
* 获取本机MAC地址
* @return list
* @throws SocketException
*/
public static String getLocalMacLiunx() throws SocketException {
String mac = "";
Set<String> macSet = new HashSet<>();
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);
Enumeration<NetworkInterface> networks = NetworkInterface.getNetworkInterfaces();
while (networks.hasMoreElements()) {
NetworkInterface network = networks.nextElement();
if (!network.isLoopback() && network.getHardwareAddress() != null) {
byte[] macBytes = network.getHardwareAddress();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < macBytes.length; i++) {
sb.append(String.format("%02x", macBytes[i]));
if (i < macBytes.length - 1) {
sb.append(":");
}
}
br.close();
} catch (IOException var6) {
System.out.println("["+sb.toString()+"]");
macSet.add(sb.toString());
}
}
} catch (SocketException e) {
System.out.println("获取MAC地址失败: " + e.getMessage());
}
mac = String.join(",", macSet);
System.out.println("本机MAC地址为:\n" + 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) {
// 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";
System.out.println("加密之前:" + content);
String encrypt = AesTool.encrypt(content, password);
System.out.println("加密后的内容:" + encrypt);
String decrypt = AesTool.decrypt(encrypt, password);
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论