# machine-uid
Get os native machine id without root permission.
[![machine-uid on GitHub Action][action-image]][action]
[![machine-uid on crates.io][cratesio-image]][cratesio]
[![total downloads][downloads-image]][cratesio]
[![machine-uid on docs.rs][docsrs-image]][docsrs]
[action-image]: https://github.com/Hanaasagi/machine-uid/actions/workflows/rust.yml/badge.svg
[action]: https://github.com/Hanaasagi/machine-uid/actions/workflows/rust.yml
[cratesio-image]: https://img.shields.io/crates/v/machine-uid.svg
[downloads-image]: https://img.shields.io/crates/d/machine-uid
[cratesio]: https://crates.io/crates/machine-uid
[docsrs-image]: https://docs.rs/machine-uid/badge.svg
[docsrs]: https://docs.rs/machine-uid
### 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.
### Usage
```Rust
extern crate 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:
```Bash
cat /var/lib/dbus/machine-id # or /etc/machine-id
```
BSD:
```Bash
cat /etc/hostid # or kenv -q smbios.system.uuid
```
OSX:
```Bash
Windows:
```powershell
(Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography).MachineGuid
```
### Supported Platform
I have tested in following platform:
- Debian 8
- OS X 10.6
- FeeBSD 10.4
- Fedora 28
- Windows 10
### License
[MIT License](https://github.com/Hanaasagi/machine-id/blob/master/LICENSE) Copyright (c) 2018, Hanaasagi