跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • Linux 系统如何获取 像 Windows 系统下所谓的机器码?
未分類
11 1 月 2021

Linux 系统如何获取 像 Windows 系统下所谓的机器码?

Linux 系统如何获取 像 Windows 系统下所谓的机器码?

資深大佬 : AmrtaShiva 4

如题 知道个 dmidecode |grep -i uuid 然而这没法写到代码里面….而且还需要 root 权限….

大佬有話說 (10)

  • 資深大佬 : codehz

    (现在流行读 mac 地址)

  • 主 資深大佬 : AmrtaShiva

    @codehz ….

  • 資深大佬 : zlowly

    读取 /sys/class/dmi/id/product_uuid,当然也可以用主板序列号 /sys/class/dmi/id/board_serial,不过都是需要 root 权限。

  • 資深大佬 : ysc3839

    那 Windows 下是如何实现的呢?

  • 主 資深大佬 : AmrtaShiva

    @zlowly 就是不想用 root 权限读取

  • 主 資深大佬 : AmrtaShiva

    @ysc3839 嘿嘿 网上一抓一大把

  • 資深大佬 : omph

    /etc/machine-id
    需要 systemd

  • 資深大佬 : zlowly

    那感觉不大可行,ls -al /sys/class/dmi/id/可以看到 product_uuid,board_serial,product_serial,chassis_serial 这几个是特意设置成只有 root 可读的,应该是 Linux 的安全特性。
    要绕过它除非象 lshal 那种方式,另外安装以 root 权限跑的 hald 服务来收集系统信息,这样才能用普通用户读取这些收集后的信息。
    用 /etc/machine-id 的话,有个问题就是这个只是在系统安装后一次性生成的,对于象在云平台基于模板克隆的系统很可能会未做处理出现重复,还真不如 MAC 比较好。

  • 資深大佬 : ysc3839

    @AmrtaShiva 随手搜到了一篇文章 https://blog.csdn.net/qq_29542611/article/details/88321102
    按照这里面的方法:
    1. 猜测对应的是 /sys/class/dmi/id/product_uuid
    2. 帮你找到了这个 property 的 description:
    The ProcessorId property contains processor-specific information that describes the processor’s features. For x86 class CPUs, the field’s format depends on the processor’s support of the CPUID instruction. If the instruction is supported, the ProcessorId property contains two DWORD-formatted values. The first (offsets 08h-0Bh) is the EAX value returned by a CPUID instruction with input EAX set to 1. The second (offsets 0Ch-0Fh) is the EDX value returned by that instruction. Only the first two bytes of the ProcessorID property are significant (all others are set to 0) and contain (in WORD-format) the contents of the DX register at CPU reset.
    3. 猜测对应的是 /sys/class/dmi/id/board_serial
    4. https://unix.stackexchange.com/questions/121757/harddisk-serial-number-from-terminal https://unix.stackexchange.com/questions/364456/getting-hard-disk-drive-serial-number-at-the-terminal-not-the-wwn 参考对应工具的源代码
    5. 参考 iproute2 的源代码

  • 主 資深大佬 : AmrtaShiva

    @ysc3839 好的 谢谢

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具