How to uniquely identify computer using C#?

2019-01-14 00:05发布

问题:

How to uniquely identify computer (mainboard) using C#(.Net/Mono, local application)?

Edition. We can identify mainboard in .Net using something like this (see Get Unique System Identifiers in C#):

using System.Management;
...
ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_MotherboardDevice");
...

But unfortunately Mono does not support System.Management. How to do it under Mono for Linux? - I don't know :(

回答1:

How about the MAC address of the network card?



回答2:

Write a function that takes a few unique hardware parameters as input and generates a hash out of them.

For example, Windows activation looks at the following hardware characteristics:

  • Display Adapter
  • SCSI Adapter
  • IDE Adapter (effectively the motherboard)
  • Network Adapter (NIC) and its MAC Address
  • RAM Amount Range (i.e., 0-64mb, 64-128mb, etc.)
  • Processor Type
  • Processor Serial Number
  • Hard Drive Device
  • Hard Drive Volume Serial Number (VSN)
  • CD-ROM / CD-RW / DVD-ROM

You can pick up a few of them to generate your unique computer identifier.



回答3:

Please see: Get Unique System Identifiers in C#



回答4:

Try this:

http://carso-owen.blogspot.com/2007/02/how-to-get-my-motherboard-serial-number.html

Personally though, I'd go with hard drive serial number. If a mainboard dies and is replaced, that PC isn't valid any more. If the HDD drive is replaced, it doesn't matter too much because the software was on it.

Of course, on the other hand, if the HDD is just moved elsewhere, the information goes with it, so you might want to look at a combination of serial numbers, depending what you want it for.



回答5:

You realistically have MotherboardID, CPUID, Disk Serial and MAC address, from experience none of them are 100%.

Our stats show

  • Disk serial Is missing 0.1 %
  • MAC Is missing 1.3 %
  • Motherboard ID Is missing 30 %
  • CPUID Is missing 99 %

0.04% of machines tested yielded no information, we couldn't even read the computer name. It maybe that these were some kind of virtual PC, HyperV or VMWare instance, or maybe just very locked down? In any case your design has to be able to cope with these cases.

Disk serial is the most reliable, but easy to change, mac can be changed and depending on the filtering applied when reading it can change if device drivers are added (hyperv, wireshark etc).

Motherboard and CPUID sometimes return values that are invalid "NONE", "AAAA..", "XXXX..." etc.

You should also note that these functions can be very slow to call (they may take a few seconds even on a fast PC), so it may be worth kicking them off on a background thread as early as possible, you ideally don't want to be blocking on them.



标签: c# .net mono