package com;
|
|
import java.io.IOException;
|
import java.nio.ByteBuffer;
|
import java.util.Scanner;
|
|
public class ComFn {
|
public static String bytesToHexString(byte[] src, int len){
|
StringBuilder stringBuilder = new StringBuilder("");
|
if (src == null || len <= 0) {
|
return null;
|
}
|
for (int i = 0; i < len; i++) {
|
int v = src[i] & 0xFF;
|
String hv = Integer.toHexString(v).toUpperCase();
|
if (hv.length() < 2) {
|
stringBuilder.append(0);
|
}
|
stringBuilder.append(hv + " ");
|
}
|
return stringBuilder.toString();
|
}
|
|
public static byte[] hexStr2Byte(String hex) {
|
ByteBuffer bf = ByteBuffer.allocate(hex.length() / 3);
|
for (int i = 0; i<hex.length(); i++) {
|
String hexStr = hex.charAt(i++) + "";
|
hexStr += hex.charAt(i++);
|
hexStr += hex.charAt(i);
|
byte b = (byte) Integer.parseInt(hexStr.trim(), 16);
|
bf.put(b);
|
}
|
return bf.array();
|
}
|
|
public String GetCpuID() {
|
try {
|
Process process = Runtime.getRuntime().exec(new String[]{"wmic", "cpu", "get", "ProcessorId"});
|
process.getOutputStream().close();
|
@SuppressWarnings("resource")
|
Scanner sc = new Scanner(process.getInputStream());
|
@SuppressWarnings("unused")
|
String property = sc.next();
|
String serial = sc.next();
|
System.out.println(serial);
|
return serial;
|
} catch (IOException ex) {
|
ex.printStackTrace();
|
}
|
return null;
|
}
|
}
|