Skip to content

Instantly share code, notes, and snippets.

@royge
Created January 27, 2018 13:07
Show Gist options
  • Save royge/9b45140aefe991abedd1d9d588fa33da to your computer and use it in GitHub Desktop.
Save royge/9b45140aefe991abedd1d9d588fa33da to your computer and use it in GitHub Desktop.
a simple example of how to grab a mac address in Golang.
// 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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment