【问题标题】:Linux Equivalent of MachineGuidMachineGuid 的 Linux 等价物
【发布时间】:2013-09-08 12:26:52
【问题描述】:

我的程序需要操作系统安装指纹,例如存储在 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\MachineGuid 中的 MSW 中的指纹 在 Microsoft Windows 中,我已经为我准备好了,但我找不到 Linux 的等价物。 Linux中是否有任何与此相关的东西?我不会有 root 访问权限,所以像 dmidecode -s system-uuid 这样的东西就不可能了。

举个例子就好了,但没必要。

【问题讨论】:

标签: c++ linux wxwidgets uniqueidentifier


【解决方案1】:

一种可能是阅读/etc/ssh/ssh_host_{d,r}sa_key.pub,所有人都可以阅读,并且在安装过程中随机生成。

显然,如果没有安装 SSH(服务器),这些文件可能根本不存在。它们也经常从旧安装中复制。

【讨论】:

  • 我明白了,但由于明显的原因,这是不可靠的,除非它们不存在时有办法生成它们。强迫用户安装它们不是一种选择!
【解决方案2】:

标准的 Unix'y 答案是主机 ID,但在实践中,这通常最终会依赖 IP 地址的哈希......

   #include <unistd.h>

   long gethostid(void);
   int sethostid(long hostid);

DESCRIPTION
   gethostid()  and  sethostid()  respectively get or set a unique 32-bit identifier for
   the current machine.  The 32-bit identifier is intended to be unique among  all  UNIX
   systems  in  existence.   This  normally resembles the Internet address for the local
   machine, as returned by gethostbyname(3), and thus usually never needs to be set.

NOTES
   In the glibc implementation, the hostid is stored in the file /etc/hostid.  (In glibc
   versions before 2.2, the file /var/adm/hostid was used.)

   In  the glibc implementation, if gethostid() cannot open the file containing the host
   ID, then it obtains the hostname using gethostname(2), passes that hostname to  geth‐
   ostbyname_r(3)  in  order  to  obtain  the  host's  IPv4 address, and returns a value
   obtained by bit-twiddling the IPv4 address.  (This value may not be unique.)

【讨论】:

  • 在动态 IP 寻址的情况下它是如何工作的。我的意思是如果计算机连接到 DHCP 服务器?每次电脑启动时“无法打开包含主机ID的文件”会不会每次都变?
  • 是的,在这种情况下几乎必须这样做。
【解决方案3】:

我假设您尝试这样做是因为您想将软件“锁定”到特定的硬件?

一种选择是使用网络接口的 MAC 地址来识别当前机器。 MAC 地址相当容易获得,请参阅this Stackoverflow question

这很好地解决了更改 IP 等问题,因为除非有人更换网卡,否则接口的 MAC 地址不太可能更改。

【讨论】:

  • 我想将其锁定到特定的操作系统签名,例如 Windows 生成的签名,但将其可靠地绑定到硬件甚至会是一个更好的解决方案。
【解决方案4】:

我认为 MAC 地址不是识别机器的好选择。有许多 USB 加密狗可以插入 PC 以提供移动/3G/H+/等。网络接口,因此当这样的加密狗插入机器时,它将具有从可用网络接口 MAC 地址派生的不同 ID。

/etc/machine-id (/var/lib/dbus/machine-id) 在您的目标系统上可用吗?

见:http://man7.org/linux/man-pages/man5/machine-id.5.html

见:http://0pointer.de/blog/projects/ids.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-08
    • 2018-07-10
    • 2019-05-10
    • 2021-03-01
    • 2013-03-20
    • 2010-12-07
    • 2010-12-28
    相关资源
    最近更新 更多