doutuanxiao4619
2017-06-23 07:07 阅读 130
已采纳

Golang库可获取序列号和便携式计算机?

Want to know a way to get the serial number and make of a laptop using some golang code.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    doujiu1447 doujiu1447 2017-06-23 09:37

    No easy answer for this, as this is OS-specific. One option is to use os/exec package and parse command output (different command for Windows, Linux and OS X). For example to obtain serial number on:

    • Windows: wmic bios get serialnumber

    • Linux: dmidecode -t system

    • OS X: ioreg -l

    Then combined with Go code for OS X case:

    out, _ := exec.Command("/usr/sbin/ioreg", "-l").Output() // err ignored for brevity
    for _, l := range strings.Split(string(out), "
    ") {
        if strings.Contains(l, "IOPlatformSerialNumber") {
            s := strings.Split(l, " ")
            fmt.Printf("%s
    ", s[len(s)-1])
        }
    }
    
    点赞 评论 复制链接分享

相关推荐