i want to get a unique serial number in every computer for a java program what can i use ? is Mac address good hat is the code for my problem ? a already have these two which one is better ?
public static void main(String[] args){
InetAddress ip;
try {
ip = InetAddress.getLocalHost();
System.out.println("Current IP address : " + ip.getHostAddress());
NetworkInterface network = NetworkInterface.getByInetAddress(ip);
byte[] mac = network.getHardwareAddress();
System.out.print("Current MAC address : ");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mac.length; i++) {
sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
}
System.out.println(sb.toString());
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (SocketException e){
e.printStackTrace();
}
}
}
public static void main(String[] args) throws Throwable {
// wmic command for diskdrive id: wmic DISKDRIVE GET SerialNumber
// wmic command for cpu id : wmic cpu get ProcessorId
//wmic command for bios :wmic bios get serialnumber
Process process = Runtime.getRuntime().exec(new String[] { "wmic", "csproduct", "get", "uuid" });
process.getOutputStream().close();
Scanner sc = new Scanner(process.getInputStream());
String property = sc.next();
String serial = sc.next();
System.out.println(property + ": " + serial);
}
is it a good way too use ProcessorId and uuid together?