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

2019-04-11 14:33发布

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条回答
戒情不戒烟
2楼-- · 2019-04-11 15:15

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

查看更多
贪生不怕死
3楼-- · 2019-04-11 15:16
sudo dmidecode --type baseboard
查看更多
闹够了就滚
4楼-- · 2019-04-11 15:20
$ lshal | grep 'system\.hardware\.serial'
  system.hardware.serial = '<serial-number>'  (string)

Works as non-root user on FC11.

查看更多
欢心
5楼-- · 2019-04-11 15:29

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

查看更多
男人必须洒脱
6楼-- · 2019-04-11 15:33

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

查看更多
登录 后发表回答