Skip to content

sandipmavani/hardwareid

Repository files navigation

hardwareid provides support for reading the unique hardware address of most host OS's

Image of Gopher 47

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

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/sandipmavani/hardwareid

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

go get github.com/sandipmavani/hardwareid/cmd/hardwareid

Usage

package main

import (
  "fmt"
  "log"
  "github.com/sandipmavani/hardwareid"
)

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

Or even better, use securely hashed hardware IDs:

package main

import (
  "fmt"
  "log"
  "github.com/sandipmavani/hardwareid"
)

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

Function: ID() (string, error)

Returns original hardware address as a string like MM:MM:MM:SS:SS:SS.

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

Returns hashed version of the hardware 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 hardware ID).

What you get

This package returns the hardware address mac address of your system.

Do something along these lines:

package main

import (
  "crypto/hmac"
  "crypto/sha256"
  "fmt"
  "github.com/sandipmavani/hardwareid"
)

const appKey = "WowSuchNiceApp"

func main() {
  id, _ := hardwareid.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 := hardwareid.ProtectedID("myAppName")

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.

Releases

No releases published

Packages

No packages published