All Projects → denisbrodbeck → Machineid

denisbrodbeck / Machineid

Licence: mit
Get the unique machine id of any host (without admin privileges)

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Machineid

Argparse
Argument Parser for Modern C++
Stars: ✭ 680 (+61.14%)
Mutual labels:  mit-license, library, cross-platform
Structopt
Parse command line arguments by defining a struct
Stars: ✭ 323 (-23.46%)
Mutual labels:  mit-license, library, cross-platform
Midir
Cross-platform realtime MIDI processing in Rust.
Stars: ✭ 221 (-47.63%)
Mutual labels:  library, cross-platform
Litter
Litter is a pretty printer library for Go data structures to aid in debugging and testing.
Stars: ✭ 1,137 (+169.43%)
Mutual labels:  mit-license, library
Indicators
Activity Indicators for Modern C++
Stars: ✭ 1,838 (+335.55%)
Mutual labels:  mit-license, library
Raz
Modern & multiplatform game engine in C++17
Stars: ✭ 161 (-61.85%)
Mutual labels:  library, cross-platform
Uriparser
🔪 Strictly RFC 3986 compliant URI parsing and handling library written in C89; moved from SourceForge to GitHub
Stars: ✭ 163 (-61.37%)
Mutual labels:  library, cross-platform
Tabulate
Table Maker for Modern C++
Stars: ✭ 862 (+104.27%)
Mutual labels:  mit-license, library
Cute headers
Collection of cross-platform one-file C/C++ libraries with no dependencies, primarily used for games
Stars: ✭ 3,274 (+675.83%)
Mutual labels:  library, cross-platform
Csconsoleformat
.NET C# library for advanced formatting of console output [Apache]
Stars: ✭ 296 (-29.86%)
Mutual labels:  library, cross-platform
Borealis
Hardware accelerated, controller and TV oriented UI library for PC and Nintendo Switch (libnx).
Stars: ✭ 135 (-68.01%)
Mutual labels:  library, cross-platform
Td
Cross-platform library for building Telegram clients
Stars: ✭ 4,260 (+909.48%)
Mutual labels:  library, cross-platform
Kivymd
Set of widgets for Kivy inspired by Google's Material Design.
Stars: ✭ 107 (-74.64%)
Mutual labels:  library, cross-platform
Gwork
Skinnable GUI with useful widget collection. Fork of GWEN.
Stars: ✭ 179 (-57.58%)
Mutual labels:  library, cross-platform
Xdg
Go implementation of the XDG Base Directory Specification and XDG user directories
Stars: ✭ 88 (-79.15%)
Mutual labels:  library, cross-platform
Igropyr
a async http server base on libuv for Chez Scheme
Stars: ✭ 85 (-79.86%)
Mutual labels:  library, cross-platform
Pycnn
Image Processing with Cellular Neural Networks in Python
Stars: ✭ 509 (+20.62%)
Mutual labels:  library, cross-platform
Plog
Portable, simple and extensible C++ logging library
Stars: ✭ 1,061 (+151.42%)
Mutual labels:  library, cross-platform
Csv
[DEPRECATED] See https://github.com/p-ranav/csv2
Stars: ✭ 237 (-43.84%)
Mutual labels:  mit-license, library
Reproc
A cross-platform (C99/C++11) process library
Stars: ✭ 325 (-22.99%)
Mutual labels:  library, cross-platform

machineid provides support for reading the unique machine id of most host OS's (without admin privileges)

Image of Gopher 47

… because sometimes you just need to reliably identify your machines.

GoDoc Go Report Card

Main Features

  • Cross-Platform (tested on Win7+, Debian 8+, Ubuntu 14.04+, OS X 10.6+, FreeBSD 11+)
  • No admin privileges required
  • Hardware independent (no usage of MAC, BIOS or CPU — those are too unreliable, especially in a VM environment)
  • IDs are unique1 to the installed OS

Installation

Get the library with

go get github.com/denisbrodbeck/machineid

You can also add the cli app directly to your $GOPATH/bin with

go get github.com/denisbrodbeck/machineid/cmd/machineid

Usage

package main

import (
  "fmt"
  "log"
  "github.com/denisbrodbeck/machineid"
)

func main() {
  id, err := machineid.ID()
  if err != nil {
    log.Fatal(err)
  }
  fmt.Println(id)
}

Or even better, use securely hashed machine IDs:

package main

import (
  "fmt"
  "log"
  "github.com/denisbrodbeck/machineid"
)

func main() {
  id, err := machineid.ProtectedID("myAppName")
  if err != nil {
    log.Fatal(err)
  }
  fmt.Println(id)
}

Function: ID() (string, error)

Returns original machine id as a string.

Function: ProtectedID(appID string) (string, error)

Returns hashed version of the machine ID as a string. The hash is generated in a cryptographically secure way, using a fixed, application-specific key (calculates HMAC-SHA256 of the app ID, keyed by the machine ID).

What you get

This package returns the OS native machine UUID/GUID, which the OS uses for internal needs.

All machine IDs are usually generated during system installation and stay constant for all subsequent boots.

The following sources are used:

  • BSD uses /etc/hostid and smbios.system.uuid as a fallback
  • Linux uses /var/lib/dbus/machine-id (man)
  • OS X uses IOPlatformUUID
  • Windows uses the MachineGuid from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography

Unique Key Reliability

Do note, that machine-id and MachineGuid can be changed by root/admin, although that may not come without cost (broken system services and more). Most IDs won't be regenerated by the OS, when you clone/image/restore a particular OS installation. This is a well known issue with cloned windows installs (not using the official sysprep tools).

Linux users can generate a new id with dbus-uuidgen and put the id into /var/lib/dbus/machine-id and /etc/machine-id. Windows users can use the sysprep toolchain to create images, which produce valid images ready for distribution. Such images produce a new unique machine ID on each deployment.

Security Considerations

A machine ID uniquely identifies the host. Therefore it should be considered "confidential", and must not be exposed in untrusted environments. If you need a stable unique identifier for your app, do not use the machine ID directly.

A reliable solution is to hash the machine ID in a cryptographically secure way, using a fixed, application-specific key.

That way the ID will be properly unique, and derived in a constant way from the machine ID but there will be no way to retrieve the original machine ID from the application-specific one.

Do something along these lines:

package main

import (
  "crypto/hmac"
  "crypto/sha256"
  "fmt"
  "github.com/denisbrodbeck/machineid"
)

const appKey = "WowSuchNiceApp"

func main() {
  id, _ := machineid.ID()
  fmt.Println(protect(appKey, id))
  // Output: dbabdb7baa54845f9bec96e2e8a87be2d01794c66fdebac3df7edd857f3d9f97
}

func protect(appID, id string) string {
  mac := hmac.New(sha256.New, []byte(id))
  mac.Write([]byte(appID))
  return fmt.Sprintf("%x", mac.Sum(nil))
}

Or simply use the convenience API call:

hashedID, err := machineid.ProtectedID("myAppName")

Snippets

Don't want to download code, and just need a way to get the data by yourself?

BSD:

cat /etc/hostid
# or (might be empty)
kenv -q smbios.system.uuid

Linux:

cat /var/lib/dbus/machine-id
# or when not found (e.g. Fedora 20)
cat /etc/machine-id

OS X:

ioreg -rd1 -c IOPlatformExpertDevice | grep IOPlatformUUID

Windows:

reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography /v MachineGuid

or

  • Open Windows Registry via regedit
  • Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography
  • Take value of key MachineGuid

Credits

The Go gopher was created by Denis Brodbeck with gopherize.me, based on original artwork from Renee French.

License

The MIT License (MIT) — Denis Brodbeck. Please have a look at the LICENSE.md for more details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].