From 4a8159a3a5180aae127fabb1dc3c79019dc5842f Mon Sep 17 00:00:00 2001 From: kasuganosoras Date: Tue, 25 Jun 2019 04:58:05 +0800 Subject: [PATCH] Add golang version --- go-version/main.go | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 go-version/main.go diff --git a/go-version/main.go b/go-version/main.go new file mode 100755 index 0000000..577287b --- /dev/null +++ b/go-version/main.go @@ -0,0 +1,49 @@ +package main + +import ( + "encoding/hex" + "crypto/hmac" + "crypto/sha1" + "strings" + "regexp" + "fmt" + "os" +) + +func hex2bin(s string) (string) { + decoded, err := hex.DecodeString(s) + if err != nil { + return "" + } + return fmt.Sprintf("%s", decoded) +} + +func main() { + if len(os.Args) == 2 { + mac := strings.Replace(os.Args[1], ":", "", -1) + if m, _ := regexp.MatchString(`^(\w+)$`, mac); !m { + fmt.Println("Invalid Mac Address!") + } else { + h := hmac.New(sha1.New, []byte(hex2bin("8544E3B47ECA58F9583043F8"))) + h.Write([]byte(hex2bin(mac))) + key := hex.EncodeToString(h.Sum(nil))[0:24] + result := "" + s := 0 + keylen := len([]rune(key)) + for i := 0; i < keylen; i++ { + s++ + result += string(key[i]) + if s == 4 && i != keylen - 1 { + result += "-" + s = 0 + } + } + fmt.Println(result) + } + } else { + fmt.Println("Supermicro IPMI License Generator") + fmt.Println("https://github.com/kasuganosoras/SuperMicro-IPMI-LicenseGenerator") + fmt.Println("Argument is missing, please append your BMC-MAC after this command.") + fmt.Println("Example: " + os.Args[0] + " 0c:c4:7a:3e:2f:de") + } +}