Created
April 17, 2015 16:04
-
-
Save stresler/e28bfa894640c393a690 to your computer and use it in GitHub Desktop.
Go Function to generate a random MAC address.
This file contains 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
func GenerateMac() (net.HardwareAddr) { | |
buf := make([]byte, 6) | |
var mac net.HardwareAddr | |
_, err := rand.Read(buf) | |
if err != nil {} | |
// Set the local bit | |
buf[0] |= 2 | |
mac = append(mac, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]) | |
return mac | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment