golang 获取CPUID,主板ID(windows)
网上查了好多大多都是linux的,然后自己使用os/exec 使用命令获取windows硬件信息 比如cpu的id 主板的id
代码:
package main
import (
"fmt"
"os/exec"
"strings"
)
//GetCPUID 获取cpuid
func GetCPUID() string {
var cpuid string
cmd := exec.Command("wmic", "cpu", "get", "processorid")
b, e := cmd.CombinedOutput()
if e == nil {
cpuid = string(b)
cpuid = cpuid[12 : len(cpuid)-2]
cpuid = strings.ReplaceAll(cpuid, "\n", "")
} else {
fmt.Printf("%v", e)
}
return cpuid
}
//GetBaseBoardID 获取主板的id
func GetBaseBoardID() string {
var cpuid string
cmd := exec.Command("wmic", "baseboard", "get", "serialnumber")
b, e := cmd.CombinedOutput()
if e == nil {
cpuid = string(b)
cpuid = cpuid[12 : len(cpuid)-2]
cpuid = strings.ReplaceAll(cpuid, "\n", "")
} else {
fmt.Printf("%v", e)
}
return cpuid
}
不想平凡,奈何太懒 T_T