Last active
August 8, 2021 09:02
-
-
Save White2001Offl/7a412bd0b5c9b291cf9bb3c113e7772b to your computer and use it in GitHub Desktop.
Generate Hardware ID in golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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