Skip to content

Instantly share code, notes, and snippets.

@DefProc
Created January 5, 2015 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DefProc/4f1122d9f591746b554a to your computer and use it in GitHub Desktop.
Save DefProc/4f1122d9f591746b554a to your computer and use it in GitHub Desktop.
generate random locally administered MAC address
# choose the leading octet:
echo -en '\x06' | xxd -b
# gives:
# 0000000: 00000110
# where these ↑↑ digits must be 10
# i.e. an octet with the the hex representation x2, x6, xA or xE
# then take the chosen octet and append a random number:
echo -n "06:" ; openssl rand -hex 5 | sed 's/\(..\)/\1:/g; s/.$//'
# if lots need generating, use the first as the initial, and increment the number so there's no collisions
# (only a worry with amounts over about 500,000 — see the birthday problem)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment