parent
ad42458550
commit
bea013d7fe
@ -0,0 +1,30 @@
|
||||
package com.zhehekeji.common.encryptor;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class Encryptor {
|
||||
public static String encryptStr(String str){
|
||||
long ulMacTmp = 0;
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
ulMacTmp = ulMacTmp << 4;
|
||||
char cStr = str.charAt(i);
|
||||
if (cStr >= '0' && cStr <= '9') {
|
||||
ulMacTmp += (long)(str.charAt(i) - '0');
|
||||
} else if (cStr >= 'a' && cStr <= 'f') {
|
||||
ulMacTmp += (long)(str.charAt(i) - 'a' + 10);
|
||||
} else if (cStr >= 'A' && cStr <= 'F') {
|
||||
ulMacTmp += (long)(str.charAt(i) - 'A' + 10);
|
||||
} else {
|
||||
ulMacTmp += 0;
|
||||
}
|
||||
}
|
||||
str = String.valueOf(ulMacTmp);
|
||||
return str;
|
||||
}
|
||||
public static void main(String[] args)
|
||||
{
|
||||
|
||||
String noEncrypt = "BFEBFBFF000B06710025_38BC_21C3_A29D.";
|
||||
String encrypt = Encryptor.encryptStr(noEncrypt);
|
||||
System.out.println(encrypt);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,149 @@
|
||||
package com.zhehekeji.filter.aspect;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.sun.management.OperatingSystemMXBean;
|
||||
import com.zhehekeji.common.encryptor.Encryptor;
|
||||
import com.zhehekeji.common.util.FileUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Scanner;
|
||||
|
||||
@Slf4j
|
||||
public class LPLicense {
|
||||
|
||||
private static LocalDateTime lastUpdate = null;
|
||||
|
||||
private static String lic_str = null;
|
||||
|
||||
private static String lic_path = "./lp.lic";
|
||||
|
||||
private static String key_path = "./lp.key";
|
||||
|
||||
private static String CPU_INFO = null;
|
||||
|
||||
private static String DEVICE_INFO = null;
|
||||
|
||||
/**
|
||||
* 初始的时候创建
|
||||
*/
|
||||
public static void createLicKeyIfNotExist() {
|
||||
File file = new File(key_path);
|
||||
if (!file.exists()) {
|
||||
String cpu = getCpuInfo();
|
||||
CPU_INFO = cpu;
|
||||
String device = getDeviceId();
|
||||
DEVICE_INFO = device;
|
||||
FileUtil.save(cpu + device, key_path);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getCpuInfo() {
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
String command = "";
|
||||
if (os.contains("win")) {
|
||||
command = "wmic cpu get ProcessorId";
|
||||
} else if (os.contains("nix") || os.contains("nux") || os.contains("mac")) {
|
||||
command = "dmidecode -t processor | grep ID";
|
||||
} else {
|
||||
return "Unsupported operating system";
|
||||
}
|
||||
|
||||
try {
|
||||
Process process = Runtime.getRuntime().exec(command);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
StringBuilder output = new StringBuilder();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
output.append(line.trim());
|
||||
}
|
||||
reader.close();
|
||||
|
||||
if (os.contains("win")) {
|
||||
return output.substring(output.indexOf("Id") + 1).trim();
|
||||
} else if (os.contains("nix") || os.contains("nux") || os.contains("mac")) {
|
||||
return output.toString().replace("ID:", "").trim();
|
||||
} else {
|
||||
return "Unknown CPU ID";
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return "Error retrieving CPU ID";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(getDeviceId());
|
||||
}
|
||||
private static String getDeviceId() {
|
||||
String deviceId = null;
|
||||
try {
|
||||
Process process = Runtime.getRuntime().exec("sudo dmidecode -s system-uuid");
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
deviceId = reader.readLine();
|
||||
reader.close();
|
||||
process.waitFor();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return deviceId != null ? deviceId : "Unknown";
|
||||
}
|
||||
|
||||
private static boolean isVirtualNetworkInterface(NetworkInterface networkInterface) throws SocketException {
|
||||
return networkInterface.isVirtual() || networkInterface.getName().contains("Virtual");
|
||||
}
|
||||
private static String getDiskInfo() {
|
||||
try {
|
||||
Process process = Runtime.getRuntime().exec(
|
||||
new String[]{"lshw", "-c", "network", "|", "grep serial", "|", "head -n 1"});
|
||||
process.getOutputStream().close();
|
||||
Scanner sc = new Scanner(process.getInputStream());
|
||||
String property = sc.next();
|
||||
String disk = sc.next();
|
||||
return disk;
|
||||
} catch (IOException e) {
|
||||
log.error("Get DISK error:{}", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getLic() {
|
||||
//每小时读取一次lic文件
|
||||
if (lastUpdate == null || LocalDateTime.now().toLocalTime().getHour() != lastUpdate.toLocalTime().getHour()) {
|
||||
lastUpdate = LocalDateTime.now();
|
||||
lic_str = FileUtil.getText(lic_path);
|
||||
CPU_INFO = getCpuInfo();
|
||||
DEVICE_INFO = getDeviceId();
|
||||
}
|
||||
return lic_str;
|
||||
}
|
||||
|
||||
public static boolean checkLic(String licStr) {
|
||||
return CPU_INFO != null && DEVICE_INFO != null && licStr.equals(Encryptor.encryptStr(CPU_INFO + DEVICE_INFO));
|
||||
|
||||
}
|
||||
|
||||
public static boolean checkLic() {
|
||||
String licStr = getLic();
|
||||
if (StringUtils.isEmpty(licStr)) {
|
||||
return false;
|
||||
}
|
||||
return checkLic(licStr);
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
//
|
||||
// createLicKeyIfNotExist();
|
||||
//
|
||||
// }
|
||||
}
|
||||
Binary file not shown.
Loading…
Reference in New Issue