Skip to content

Instantly share code, notes, and snippets.

@White2001Offl
Last active August 8, 2021 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save White2001Offl/7a412bd0b5c9b291cf9bb3c113e7772b to your computer and use it in GitHub Desktop.
Save White2001Offl/7a412bd0b5c9b291cf9bb3c113e7772b to your computer and use it in GitHub Desktop.
Generate Hardware ID in golang
// go get github.com/jaypipes/ghw
// go get github.com/pkg/errors
package main
import (
"github.com/jaypipes/ghw"
"github.com/pkg/errors"
"crypto/md5"
"encoding/hex"
)
func md5Hash(data string) string{
hash := md5.New()
hash.Write([]byte(data))
return hex.EncodeToString(hash.Sum(nil))
}
func GetHardwareID() (string, error){
info , err := ghw.CPU()
if err != nil{
return "", errors.New(err.Error())
}
bios , err := ghw.BIOS()
if err != nil{
return "", errors.New(err.Error())
}
base , err := ghw.Baseboard()
if err != nil{
return "", errors.New(err.Error())
}
Block , err := ghw.Block()
if err != nil{
return "", errors.New(err.Error())
}
data := Block.String() + base.String() + bios.String() + info.String()
return md5Hash(data) , nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment