Skip to content

Instantly share code, notes, and snippets.

@midwire
Created July 10, 2014 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save midwire/79033f2b05f836ecf51b to your computer and use it in GitHub Desktop.
Save midwire/79033f2b05f836ecf51b to your computer and use it in GitHub Desktop.
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