Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Generate a random MAC address
# Generate a random MAC address with a known vendor prefix from the nmap mac
# prefixes file.
# Tim van Werkoven, 20100405 <>
# This file is licensed under the Creative Commons Attribution-Share Alike
# license versions 3.0 or higher, see
## Get a random prefix from a nmap-mac-prefixes file
LINES=`wc -l $MACFILE | awk '{print$1}'`;
## Select a random line from the file
## Line syntax is <prefix> <vendor>, with <prefix> a 6 digit hexadecimal
## number. Add colons and convert to lowercase if necessary.
VENDOR=`head -n $RANDLINE $MACFILE | tail -n 1 | awk '{print$2}'`
PREFIX=`head -n $RANDLINE $MACFILE | tail -n 1 | awk '{print$1}' | sed -n 's/\(..\)\(..\)\(..\)/\1:\2:\3/p' | tr [:upper:] [:lower:]`
## Using the fixed prefix, fill in the remaining 6 digits with random numbers
while [ $i -lt 3 ]; do
printf -v MACADDR "%s:%02x" $MACADDR `expr $RANDOM % 255`
let i+=1
printf "Vendor: %s, vendor prefix: %s, MAC: %s\n" $VENDOR $PREFIX $MACADDR
printf "sudo ifconfig en1 lladdr $PREFIX\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.