tags:

views:

707

answers:

2

How to obtain motherboard and processor unique identifiers in Mono under Linux?

Note: .Net namespace System.Management has no counterpart in Mono

+1  A: 

I see two potential ways:

  • Start the uname/motherboard info console program within your code, using ProcessStartInfo.RedirectStandardInput (and output/error) to parse the output
  • Access the proper C-functions using DllImport directive (if uname -a is not good enough). Remember to set your LD_LIBRARY_PATH accordingly so that the shared library can be found.
weismat
+1  A: 

The typical approach from the command line is using dmidecode or lshw, which read the BIOS DMI area, and parse the serial numbers. However, this won't work if your application doesn't run as root, since it needs to be able to read /dev/mem.

You can get some of this information through HAL. I'm not entirely sure how to do this through HAL directly, but you can do it through the lshal command. Under one of the devices shown, you should see an entry for "system.hardware.serial" and "system.hardware.uuid" - those are the motherboard's serial number and UUID.

You can query HAL from Bash like this:

PC=`hal-find-by-property --key info.product --string Computer`
PC_UUID=`hal-get-property --udi $PC --key system.hardware.uuid`
PC_SERIAL=`hal-get-property --udi $PC --key system.hardware.serial`

On older machines, those keys might be "smbios.system.uuid" and "smbios.system.serial" instead. Also, be aware that this information may not exist on all machines, or make be entirely fake. I have at least one motherboard here with a UUID consisting entirely of 1's, and another with a CPU serial number that's almost entirely zeroes.

BlackAura