Hanaasagi / machine-uid

Get machine id without root permission
https://crates.io/crates/machine-uid
MIT License
25 stars 12 forks source link
cross-platform hostid machine-id uid

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:

Changelog

v0.5.3

v0.5.2

v0.5.1

v0.5.0

v0.4.0

v0.3.0

v0.2.0

License

MIT License Copyright (c) 2018, Hanaasagi