Created
March 20, 2018 02:31
-
-
Save liasica/f4db81e8138b5b0d7978e4e55933914a to your computer and use it in GitHub Desktop.
a simple example of how to grab a mac address in Golang.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// getMacAddr gets the MAC hardware | |
// address of the host machine | |
func getMacAddr() (addr string) { | |
interfaces, err := net.Interfaces() | |
if err == nil { | |
for _, i := range interfaces { | |
if i.Flags&net.FlagUp != 0 && bytes.Compare(i.HardwareAddr, nil) != 0 { | |
// Don't use random as we have a real address | |
addr = i.HardwareAddr.String() | |
break | |
} | |
} | |
} | |
return | |
} |
invalid operation: ifa.Flags & net.FlagUp != 0 && bytes.Compare(ifa.HardwareAddr, nil) (mismatched types untyped bool and int)
bytes.Compare(i.HardwareAddr, nil) != 0
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
invalid operation: ifa.Flags & net.FlagUp != 0 && bytes.Compare(ifa.HardwareAddr, nil) (mismatched types untyped bool and int)