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

11.8k views Asked by At

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.

5

There are 5 answers

2
Allen On

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
AudioBubble On

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

3
Ben Voigt On

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).

0
Pipo On
sudo dmidecode --type baseboard
1
Peter On
$ lshal | grep 'system\.hardware\.serial'
  system.hardware.serial = '<serial-number>'  (string)

Works as non-root user on FC11.