Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Set a random MAC address on OSX
#!/bin/bash
# ether 3c:07:54:12:6d:fc
if [ -z "$1" ]; then
echo "usage: $0 NETWORK_INTERFACE(en0|en1)"
exit 1
fi
interface="$1"
mac=`openssl rand -hex 1 | \
tr '[:lower:]' '[:upper:]' | \
xargs echo "obase=2;ibase=16;" | \
bc | cut -c1-6 | sed 's/$/00/' | \
xargs echo "obase=16;ibase=2;" | bc | \
sed "s/$/:$(openssl rand -hex 5 | sed 's/\(..\)/\1:/g; s/.$//' | tr '[:lower:]' '[:upper:]')/"`
echo "Setting link-level address for [$interface] to [$mac]"
sudo ifconfig $interface ether $mac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment