Computer ID?

I am trying to create a specific computer id using Java. I was thinking about things like Serial Serial or Serial Keys Windows, CPU IDs or MAC addresses, but on other computers they might be the same. For example, if someone pirates is copying Windows 7, they may have the same serial number as someone .. I was wondering if someone could give me a way to generate a computer ID that never changes and is retrieved using Java?

I did some research and found some useful features. And I was thinking about something like that. But if they change their equipment, it will change the computer identifier. Does anyone know something that I can use?

public String getComputerID(){ InetAddress ip = InetAddress.getLocalHost(); NetworkInterface network = NetworkInterface.getByInetAddress(ip); byte[] mac = network.getHardwareAddress(); String sn = getSerialNumber("C"); String cpuId = getMotherboardSN(); return MD5(mac + sn + cpuId); } public String MD5(String md5) { try { java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); byte[] array = md.digest(md5.getBytes()); StringBuffer sb = new StringBuffer(); for (int i = 0; i < array.length; ++i) { sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1,3)); } return sb.toString(); } catch (java.security.NoSuchAlgorithmException e) { } return null; } public String getSerialNumber(String drive) { String result = ""; try { File file = File.createTempFile("realhowto",".vbs"); file.deleteOnExit(); FileWriter fw = new java.io.FileWriter(file); StringBufferring vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n" +"Set colDrives = objFSO.Drives\n" +"Set objDrive = colDrives.item(\"" + drive + "\")\n" +"Wscript.Echo objDrive.SerialNumber"; // see note fw.write(vbs); FileWriter.close(); Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath()); BufferedReader input = new BufferedReader (new InputStreamReader(p.getInputStream())); String line; while ((line = input.readLine()) != null) { result += line; } input.close(); } catch(Exception e){ e.printStackTrace(); } return result.trim(); } public String getMotherboardSN() { String result = ""; try { File file = File.createTempFile("realhowto",".vbs"); file.deleteOnExit(); FileWriter fw = new java.io.FileWriter(file); String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n" + "Set colItems = objWMIService.ExecQuery _ \n" + " (\"Select * from Win32_BaseBoard\") \n" + "For Each objItem in colItems \n" + " Wscript.Echo objItem.SerialNumber \n" + " exit for ' do the first cpu only! \n" + "Next \n"; fw.write(vbs); fw.close(); Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath()); BufferedReader input = new BufferedReader (new InputStreamReader(p.getInputStream())); String line; while ((line = input.readLine()) != null) { result += line; } input.close(); } catch(Exception e){ e.printStackTrace(); } return result.trim(); } 
+6
source share
3 answers

I really believe that you should use something from the equipment profile.
A computer can be thought of as a set of hardware, including a network interface. A typical example would be a combination of a MAC address and a generated identifier using a management system that controls computers over a network.
MAC address for unique identification of the machine during the registration process in the control system.
As a result of registration, the control system can return the generated UniqueId,
for storage on a computer registered on it and will be used later.
After successful registration, you can replace the network interface card, since the computer does not depend on the identifiable MAC address.
You can also use the linux dmidecode utility
(for Linux machines,
since you provided a win based solution,
so for our linux readers,
I would like to suggest alternatives to linux) (if the machine you want to uniquely identify has linux and dmidecoe).
Using dmidecoe, you can get more hardware profile and perform some hash function on it, as well as create a unique identifier that will uniquely identify (with a high probability, to be exact) your machine.
Read more about dmidecode here .
Of course, if you go to the โ€œget hardware information from the operating systemโ€ approach (which is dmidecode or what you suggested in this part after getting the MAC address,
You need cross-platform system code to check which OS the Java program is running in, you do this using this:

 System.getProperty("os.name"); 
+4
source

After looking at all the input and a few google searches, I came to this conclusion

Technically speaking, seeing that you removed a component and replaced it, it would be a completely new computer to generate a true computer identifier, which would have to receive a specific variable from each component in the system (i.e. serial number), combine them everything and it will be "Computer ID". Nevertheless, since the computer is so susceptible to changes, the closest one is the transition to the LEAST LIKELY TO CHANGE component, and we have a specific variable from it for the computer identifier. This will usually be a motherboard or other component that is unlikely to change. So, the closest one may be the serial number (or some other child component) of the motherboard .. In my personal opinion.

Why does the motherboard change the least?

It seems that the motherboard is the last part that people consider to be changing, especially on new computers. They usually will not change it unless absolutely necessary. Another viable option would be a NIC. Itโ€™s honest with you which piece of equipment you are using, but the best to use is the one that you think is the least likely to change.

+1
source

For disks / volumes, this could be:

  /** * Execute system console command 'vol' and retrieve volume serial number * * @param driveLetter - drive letter in convetion 'X:' * @return - Volume Serial Number, typically: 'XXXX-XXXX' * @throws IOException * @throws InterruptedException */ static final String getVolumeSerial(String driveLetter) throws IOException, InterruptedException { Process process = Runtime.getRuntime().exec("cmd /C vol " + driveLetter); InputStream inputStream = process.getInputStream(); InputStream errorStream = process.getErrorStream(); if (process.waitFor() != 0) { Scanner sce = new Scanner(errorStream); throw new RuntimeException(sce.findWithinHorizon(".*", 0)); } Scanner scn = new Scanner(inputStream); // looking for: ': XXXX-XXXX' using regex String res = scn.findWithinHorizon(": \\w+-\\w+", 0); return res.substring(2).toUpperCase().trim(); } 
+1
source

All Articles