1 Star 1 Fork 1

xiaoyutab / xgotool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
mac.go 632 Bytes
一键复制 编辑 原始数据 按行查看 历史
xiaoyutab 提交于 2023-11-02 13:17 . 调整默认MAC地址为:::cpux
package xstring
import (
"fmt"
"net"
"runtime"
)
// 获取设备网卡MAC地址,一般使用此方法来计算设备的唯一标识
func Mac() map[string]string {
mac := map[string]string{}
interfaces, err := net.Interfaces()
if err == nil {
for _, inter := range interfaces {
if len(inter.HardwareAddr) > 0 {
mac[inter.Name] = inter.HardwareAddr.String()
}
}
}
// 如果获取到的MAC地址为空的话,就直接添加一个系统+架构+未知的MAC网卡地址
if len(mac) == 0 {
mac["undefined"] = runtime.GOOS + ":" + runtime.GOARCH + fmt.Sprintf(":cpux%02d", runtime.NumCPU())
}
return mac
}
Go
1
https://gitee.com/xiaoyutab/xgotool.git
git@gitee.com:xiaoyutab/xgotool.git
xiaoyutab
xgotool
xgotool
v0.3.9

搜索帮助

53164aa7 5694891 3bd8fe86 5694891