Linux下无root权限如何获取CPU序列号

发布于 2024-10-18 00:47:21 字数 170 浏览 1 评论 0原文

在没有root权限的Linux(Ubuntu)下如何获取CPU序列号?

我尝试了 cpuid 命令,它无需 root 权限即可工作,但似乎返回全零(我相信是因为需要在 BIOS 中更改某些内容)。

您能否建议我另一种从程序中检索 CPU 序列号的方法,无需 root 权限且无需修改 BIOS?

How can I get CPU serial number under Linux (Ubuntu) without root permissions?

I tried cpuid command, it works without root permissions, but appears to return all zeros (I believe because something needs to be changed in BIOS).

Can you please suggest me another way to retrieve CPU serial from a program without root permissions and without having to modify BIOS?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

梦情居士 2024-10-25 00:47:21

处理器序列号基本上仅存在于 Pentium III 处理器中。由于提出的隐私问题,英特尔从后来的型号中删除了它。因此,除非您使用的是 PIII 并且您的 BIOS 设置允许您读取序列号,否则您将得到的只是 0。

Processor serial numbers were basically only in Pentium III processors. Intel removed it from later models due to the privacy concerns that were raised. As such, unless you're on a PIII AND your BIOS settings let you read the serial number, all you'll get are 0's.

你是年少的欢喜 2024-10-25 00:47:21

需要root权限。答案是dmidecode。
如果您需要 CPU ID:

dmidecode | grep -w ID | sed "s/^.ID\: //g"

这将获取 CPU ID,从输出中删除“ID:”
如果您需要接收计算机ID:

dmidecode | grep -w UUID | sed "s/^.UUID\: //g"

如果您希望在没有root权限的情况下获得内核uuid,那么:

dmesg | grep UUID | grep "Kernel" | sed "s/.*UUID=//g" | sed "s/\ ro\ quiet.*//g"

这是因为最近的评论。很久以前发生的事情,所以现在无法解释为什么这些 ID 被用作机器标识符。从处理器信息部分获取实际的处理器ID。在 Debian 操作系统上提取。

pr=0; dmidecode | while read line; do [ "$line" == "Processor Information" ] && pr=1; [ $pr -eq 0 ] && continue; [ -n "$(echo $line | grep '^ID')" ] && echo $line | awk -F"ID: " '{print $2}' && break; done

Root permissions required. The answer is dmidecode.
If you need CPU ID:

dmidecode | grep -w ID | sed "s/^.ID\: //g"

This will get CPU ID, remove 'ID: ' from output
If you need to receive a computer ID:

dmidecode | grep -w UUID | sed "s/^.UUID\: //g"

If you wish to get kernel uuid without root permissions, then:

dmesg | grep UUID | grep "Kernel" | sed "s/.*UUID=//g" | sed "s/\ ro\ quiet.*//g"

It's because of recent comment. Happened long time ago, so can't explain now why these ID were taken as machine identifier. Got actual Processor ID fromn Processor Information section. Extracted on Debian OS.

pr=0; dmidecode | while read line; do [ "$line" == "Processor Information" ] && pr=1; [ $pr -eq 0 ] && continue; [ -n "$(echo $line | grep '^ID')" ] && echo $line | awk -F"ID: " '{print $2}' && break; done
十六岁半 2024-10-25 00:47:21

将许可证与其可执行文件安装到用户文件系统时获得的索引节点号联系起来。如果他们被转移到其他地方,他们就会改变。

缺点是如果必须从备份恢复程序,则可能无法保留这些数字。

我以前也做过这样的事。您必须非常慷慨地让真正的用户在更改硬件时激活许可证。

Tie the license to the inode numbers that its executable files get when they are installed into the user's filesystem. If they are moved somewhere else, they will change.

The downside is that the numbers may not be preserved if the program has to be restored from a backup.

I've done this sort of thing before. You have to be very generous about letting genuine users activate the license on changing hardware.

孤寂小茶 2024-10-25 00:47:21

无论我是否使用 sudo,cpuid 都会为我返回相同的序列号:

 % cpuid | grep serial
Processor serial: 0002-0652-0000-0000-0000-0000
 % sudo cpuid | grep serial
Processor serial: 0002-0652-0000-0000-0000-0000

除非您指的是其他序列号...?

cpuid returns the same serial number for me regardless of my use of sudo:

 % cpuid | grep serial
Processor serial: 0002-0652-0000-0000-0000-0000
 % sudo cpuid | grep serial
Processor serial: 0002-0652-0000-0000-0000-0000

Unless there's some other serial number that you're referring to...?

尝蛊 2024-10-25 00:47:21

正如之前提出这个问题时所建议的,如果您尝试使用它进行许可(因为您使用了许可标签),您可能需要尝试 MAC 地址:
CPU 序列号

As suggested when this question was asked before, if you are trying to use this for licensing (since you used the licensing tag) you may want to try the MAC address:
CPU serial number

江湖正好 2024-10-25 00:47:21

这可能与发行版相关,但请尝试

cat /proc/cpuinfo

并检查序列,如下所示:

Hardware    : BCM2835
Revision    : c03115
Serial      : <....>

在没有超级用户的情况下在 Raspbian GNU/Linux 11(牛眼)上测试。

This is likely distro-dependent, but try

cat /proc/cpuinfo

And check for the serial as in:

Hardware    : BCM2835
Revision    : c03115
Serial      : <....>

Tested on Raspbian GNU/Linux 11 (bullseye) without super user.

黒涩兲箜 2024-10-25 00:47:21

CPU没有序列号;也许您想要没有 root 权限的 DMI 基本信息(这只会显示您的主板制造商和型号的持久 ID,但没有序列号):

dmesg | grep -i dmi: | cut -d ":" -f 2-

否则您可以“告诉”dmidecode 从非特权运行用户:

sudo chmod +s /usr/sbin/dmidecode

然后您可以运行例如:

dmidecode -s system-serial-number

在大多数情况下,“系统序列号”类似于“机箱序列号”或“底板序列号”。请记住,并非所有发行版都安装了此程序,例如,基于 Debian 的系统都有一个以它命名的软件包。

否则,您可以通过系统磁盘找到唯一且持久的、安装后的系统 ID;为此,您可以运行以下命令:

mount | grep "on / type" | awk '{print $1}'

前者将为您提供安装系统的设备路径(对于我的操作系统,它返回/dev/sda7),然后您可以使用以下命令找到它的ID: 因此,

find /dev/disk/by-id/ -lname "*sda" ! -name "wwn*"

从系统硬盘查找唯一 ID 的完整命令可能是:

find /dev/disk/by-id/ -lname "*`mount | grep " / " | awk '{print $1}' | cut -b 6-8`" ! -name "wwn*" -printf "%f\n"

我希望这可以满足您或其他人的需求。命令 cut -b 6-8 可能不可移植,因为我假设块设备名称为三个字符长;此外,/dev/disk/by-id/ 路径仅由 UDEV 托管系统填充,并非所有 Linux 发行版都使用它,但我向您保证前者可以在 Ubuntu 中工作。

CPUs has no serial number; maybe that you want DMI basic info without root privilege (This will only show you a persistent id of your motherboard manufacturer and model, but no serial number):

dmesg | grep -i dmi: | cut -d ":" -f 2-

Otherwise you could "tell" dmidecode to run from unprivileged user:

sudo chmod +s /usr/sbin/dmidecode

Then you could run for instance:

dmidecode -s system-serial-number

In most cases "system-serial-number" is like either "chassis-serial-number" or "baseboard-serial-number". Remember that not all distros have this program installed, for instance, Debian based systems have a package named after it.

Otherwise you can find a unique and persistent, thro' installs, system ID via your system's disk; to do that you may run the following:

mount | grep "on / type" | awk '{print $1}'

The former will give you device's path where your system is mounted (for my OS it returned /dev/sda7), and then you can find an ID for it with the following:

find /dev/disk/by-id/ -lname "*sda" ! -name "wwn*"

So the complete command to find a unique ID from your system's hard disk could be:

find /dev/disk/by-id/ -lname "*`mount | grep " / " | awk '{print $1}' | cut -b 6-8`" ! -name "wwn*" -printf "%f\n"

I hope this may fit your needs or someone else's in here. Command cut -b 6-8 may not be portable, because I'm assuming block devices names to be three chars long; moreover, /dev/disk/by-id/ path is only filled by UDEV managed systems and not all Linux distros use it, but I ensure you the former will work in Ubuntu.

何其悲哀 2024-10-25 00:47:21

您检查过dmesg吗?它在 /bin

Have you checked dmesg? Its in /bin

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文