package NetUtil import ( "fmt" "net" ) /** 功能:获取服务器的第一个网卡MAC地址 作者:黄海 时间:2020-01-19 */ func GetMacAddrs() (macAddrs []string) { netInterfaces, err := net.Interfaces() if err != nil { fmt.Printf("fail to get net interfaces: %v", err) return macAddrs } for _, netInterface := range netInterfaces { macAddr := netInterface.HardwareAddr.String() if len(macAddr) == 0 { continue } macAddrs = append(macAddrs, macAddr) } return macAddrs }