Skip to content

Instantly share code, notes, and snippets.

@mnadel
Last active December 24, 2016 02:52
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 mnadel/b5592ef34f36d96d98f359470b501d9b to your computer and use it in GitHub Desktop.
Save mnadel/b5592ef34f36d96d98f359470b501d9b to your computer and use it in GitHub Desktop.
Change your Mac's MAC
#!/usr/bin/env bash
MYMAC=$(/usr/sbin/networksetup -getmacaddress Wi-Fi | grep -oE "[a-zA-Z0-9]{2}:([a-zA-Z0-9]{2}:?)+")
if [ "$1" == "--help" ] || [ $# -gt 1 ]; then
echo "usage: $(basename $0) [--random|--orig]"
exit 1
fi
if [ $# -eq 0 ] || [ "$1" == "--random" ]; then
# force first octet to be even (end in 0,2,4,6,8,a,c,e) to indicate unicast
newmac=$(openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/./0/2; s/.$//')
elif [ "$1" == "--orig" ]; then
newmac=$MYMAC
else
echo huh?
exit 1
fi
echo disassociating
sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -z
echo setting mac to: $newmac
sudo ifconfig en0 ether "$newmac"
echo restarting en0
#networksetup -detectnewhardware
sudo ifconfig en0 down
sudo ifconfig en0 up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment