获取硬件信息
For those who would like to see ready-to-use solution, I’m including links to the three classes I wrote to get machine SN on Windows, Linux and Mac OS:- Java code to get computer SN on Windows
- Java code to get computer SN on Linux
- Java code to get computer SN on Mac OS
oshi项目
- oshi项目: Native Operating System and Hardware Information oshi.github.io/oshi/readme.html
Supported platforms
Windows • Linux • macOS • Unix (AIX, FreeBSD, OpenBSD, Solaris)参考项目:cryptolens-java
https://github.com/Cryptolens/cryptolens-java
特点
- 使用oshi项目获取硬件信息
- 支持多种语言
- API设计友好
- 商业
License校验示例
import io.cryptolens.methods.*;
import io.cryptolens.models.*;
public class Main {
public static void main(String[] args) {
String RSAPubKey = "<RSAKeyValue><Modulus>sGbvxwdlDbqFXOMlVUnAF5ew0t0WpPW7rFpI5jHQOFkht/326dvh7t74RYeMpjy357NljouhpTLA3a6idnn4j6c3jmPWBkjZndGsPL4Bqm+fwE48nKpGPjkj4q/yzT4tHXBTyvaBjA8bVoCTnu+LiC4XEaLZRThGzIn5KQXKCigg6tQRy0GXE13XYFVz/x1mjFbT9/7dS8p85n8BuwlY5JvuBIQkKhuCNFfrUxBWyu87CFnXWjIupCD2VO/GbxaCvzrRjLZjAngLCMtZbYBALksqGPgTUN7ZM24XbPWyLtKPaXF2i4XRR9u6eTj5BfnLbKAU5PIVfjIS+vNYYogteQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
String auth = "WyIyNjA5IiwiaWE5b0VFT3Q2eDlNR2FvbHBHK2VOYUZ4bzNjT3h5UkNrMCtiYnhPRSJd";
LicenseKey license = Key.Activate(auth, RSAPubKey, new ActivateModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL", Helpers.GetMachineCode()));
if (license == null || !Helpers.IsOnRightMachine(license)) {
System.out.println("The license does not work.");
} else {
System.out.println("The license is valid!");
System.out.println("It will expire: " + license.Expires);
}
}
}
获取硬件信息:
private static String getRawDeviceID()
{
//thanks to https://stackoverflow.com/a/37705082. may require root.
SystemInfo systemInfo = new SystemInfo();
OperatingSystem operatingSystem = systemInfo.getOperatingSystem();
HardwareAbstractionLayer hardwareAbstractionLayer = systemInfo.getHardware();
CentralProcessor centralProcessor = hardwareAbstractionLayer.getProcessor();
ComputerSystem computerSystem = hardwareAbstractionLayer.getComputerSystem();
String vendor = operatingSystem.getManufacturer();
String processorSerialNumber = computerSystem.getSerialNumber();
String processorIdentifier = centralProcessor.getProcessorIdentifier().getIdentifier();
int processors = centralProcessor.getLogicalProcessorCount();
return vendor +
processorSerialNumber +
processorIdentifier +
processors;
}