machineid

package module
v0.0.0-...-4283e98 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2025 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Overview

Package machineid provides a way to get a unique identifier for the current machine without using any internal hardware IDs. As a result, it doesn't require any special permissions to run and works in unprivileged containers as well.

The returned ID is generally stable for the OS installation and usually stays the same after updates or hardware changes.

Caveat: Image-based environments usually have the same machine-id (perfect clones). 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.

This is based on https://github.com/denisbrodbeck/machineid which is no longer maintained.

Example
package main

import (
	"fmt"

	machineid "github.com/columnar-tech/machine-id"
)

func main() {
	id, err := machineid.ID()
	if err != nil {
		panic(err)
	}
	fmt.Println(id)
}
Example (ProtectedID)
package main

import (
	"fmt"

	machineid "github.com/columnar-tech/machine-id"
)

func main() {
	id, err := machineid.ProtectedID()
	if err != nil {
		panic(err)
	}

	fmt.Println(id)
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ID

func ID() (string, error)

ID returns the platform specific machine id of the current host OS. Consider the returned id as "confidential" information and consider using ProtectedID() instead for privacy preserving usage.

func ProtectedID

func ProtectedID() (string, error)

ProtectedID returns an HMAC-SHA256 hashed version of the machine ID using a fixed key. This is a privacy preserving way to use the machine ID as it is not reversible and the same on every call on the same machine.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL