8 releases (4 breaking)

0.5.3 Aug 17, 2024
0.5.2 Jun 30, 2024
0.5.1 Aug 8, 2023
0.5.0 Jul 29, 2023
0.1.0 Oct 2, 2018

#48 in Operating systems

Download history 4125/week @ 2024-07-21 4600/week @ 2024-07-28 5000/week @ 2024-08-04 4838/week @ 2024-08-11 7676/week @ 2024-08-18 9892/week @ 2024-08-25 8856/week @ 2024-09-01 10021/week @ 2024-09-08 9054/week @ 2024-09-15 13459/week @ 2024-09-22 10781/week @ 2024-09-29 6359/week @ 2024-10-06 8495/week @ 2024-10-13 10282/week @ 2024-10-20 10334/week @ 2024-10-27 11996/week @ 2024-11-03

41,510 downloads per month
Used in 37 crates (22 directly)

MIT license

11KB
138 lines

machine-uid

Get os native machine id without root permission.

machine-uid on GitHub Action machine-uid on crates.io total downloads machine-uid on docs.rs

About machine id

In Linux, machine id is a single newline-terminated, hexadecimal, 32-character, lowercase ID. When decoded from hexadecimal, this corresponds to a 16-byte/128-bit value. This ID may not be all zeros. This ID uniquely identifies the host. It should be considered "confidential", and must not be exposed in untrusted environments. And do note that the machine id can be re-generated by root.

Please note that on *nix platforms, this library does not require any dependencies, but on Windows, it requires the winreg dependency. So if you only need to build the *nix version, you can use version 0.3.0.

Usage

use machine_uid;

fn main() {
    let id: String = machine_uid::get().unwrap();
    println!("{}", id);
}

How it works

It get machine id from following source:

Linux or who use systemd:

cat /var/lib/dbus/machine-id # or /etc/machine-id

BSD:

cat /etc/hostid # or kenv -q smbios.system.uuid

OSX:

ioreg -rd1 -c IOPlatformExpertDevice | grep IOPlatformUUID

Windows:

(Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography).MachineGuid

illumos:

gethostid(3C)

Supported Platform

I have tested in following platform:

  • Debian 8
  • OS X 10.6
  • FreeBSD 10.4
  • Fedora 28
  • Windows 10
  • OmniOS r151050

Changelog

v0.5.3

  • Remove built in C dependency #13

v0.5.2

  • Add illumos support #11
  • Upgrade winreg to 0.52 #12
  • Upgrade bindgen to 0.69 #12

v0.5.1

  • Upgrade winreg to 0.50 #9
  • Upgrade bindgen to 0.66 #8

v0.5.0

  • Fix cross-compilation issue #7

v0.4.0

  • Fix x86 program run on x64 #4

v0.3.0

  • Upgrade winreg to 0.11

v0.2.0

  • Added support for Windows

License

MIT License Copyright (c) 2018, Hanaasagi

Dependencies

~0–9.5MB
~42K SLoC