Created
July 10, 2014 14:01
-
-
Save midwire/79033f2b05f836ecf51b to your computer and use it in GitHub Desktop.
Set a random MAC address on OSX
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
#!/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