gitee.com/quant1x/gox@v1.21.2/devices/cpu_linux.go (about)

     1  //go:build linux
     2  
     3  package devices
     4  
     5  import (
     6  	"net"
     7  )
     8  
     9  func macAddress() (PhysicalID string, err error) {
    10  	// 获取本机的MAC地址
    11  	interfaces, err := net.Interfaces()
    12  	if err != nil {
    13  		return defaultPhysicalID, err
    14  	}
    15  	PhysicalID = defaultPhysicalID
    16  	for _, inter := range interfaces {
    17  		if inter.Name == "en0" || inter.Name == "eth0" {
    18  			//fmt.Println(inter.Name)
    19  			mac := inter.HardwareAddr //获取本机MAC地址
    20  			//fmt.Println("MAC = ", mac)
    21  			PhysicalID = mac.String()
    22  			break
    23  		}
    24  	}
    25  	return
    26  }
    27  
    28  // CpuPhysicalID linux用第一块网卡的mac地址代替
    29  func CpuPhysicalID() (PhysicalID string, err error) {
    30  	return macAddress()
    31  }