Giter Site home page Giter Site logo

hanaasagi / machine-uid Goto Github PK

View Code? Open in Web Editor NEW
17.0 3.0 8.0 27 KB

Get machine id without root permission

Home Page: https://crates.io/crates/machine-uid

License: MIT License

Rust 69.78% Shell 19.76% C++ 10.46%
machine-id cross-platform uid hostid

machine-uid's Introduction

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

Supported Platform

I have tested in following platform:

  • Debian 8
  • OS X 10.6
  • FeeBSD 10.4
  • Fedora 28
  • Windows 10

Changelog

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

machine-uid's People

Contributors

21pages avatar hanaasagi avatar kinosang avatar xaf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

machine-uid's Issues

Error while cross compiling to Windows from MacOS

Hey there,

since I updated the crate version to 0.4.0 I get the following error when invoking cargo build with the following flags

cargo build --release --target x86_64-pc-windows-gnu

I'm using MacOS Ventura + the latest stable Rust toolchains.

  = note: /opt/homebrew/Cellar/mingw-w64/11.0.0/toolchain-x86_64/bin/x86_64-w64-mingw32-ld: target/x86_64-pc-windows-gnu/release/deps/libmachine_uid-298ed35685296eff.rlib(machine_uid-298ed35685296eff.machine_uid.1208bef349eb5abc-cgu.2.rcgu.o):machine_uid.1208be:(.text+0x54): undefined reference to `MachineUidIsWow64'
          collect2: error: ld returned 1 exit status

  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

I guess this was introduced via PR #4 .

My current solution is to simply downgrade to version 0.3.0.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.