How to get motherboard ID on Linux from a C++ prog

2019-04-11 14:32发布

问题:

I want to retrieve motherboard ID from a C++ program on Linux (Ubuntu) without root privileges. I know that dmidecode can do this, but it requires root privileges, so it is not suitable for my needs. Does anyone know of non-root alternatives? Source code will be much appreciated.

回答1:

You don't have to be root to get the information, but you do need to have root first give you permission. Obviously root is allowed to secure access to their machine, and this includes access to hardware identity information.

root controls what the software on their machine can do, your software does not restrict what root can do. (Linux Corollary to The #1 Law of Software Licensing)

If root chooses to install your hardware id collector, it's relatively straightforward to make that data available to non-root users (but it's also relatively easy for root to modify your id collector to lie).



回答2:

$ lshal | grep 'system\.hardware\.serial'
  system.hardware.serial = '<serial-number>'  (string)

Works as non-root user on FC11.



回答3:

lshw should get the serial for you. It will tell you it should be run as superuser but will run anyway. (tested on ubuntu)



回答4:

sudo dmidecode --type baseboard


回答5:

I think you need to be root

opening up /proc/pci will give you alot of information chipset etc, not sure if /proc/ has a specific directory for motherboard or BIOS info, have a look ls /proc ?

Other than that you could look at calling the dmidecode commandline tool from your application and capturing its output. If thats not good enough, perhaps even look at the source code of dmidecode to see how it works?

Andrew