This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
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)