I had an earlier script I was using to change my MAC address. Just one good idea of many when out and about in the wild west of public wireless.The couple of times I checked the address had changed just fine, but one day I noticed the address hadn’t changed. Huh? I tried a second time and still no luck. Well, third time was a charm, but why did the first two times fail.
I wandered over to duckduckgo and had look to see what I could find. After a few pages of not much luck, just more of what was already using, and then found some good information to know in the link below. The MAC address’ first octet has to be even; as an even first byte indicates the packet is Unicast.
Below is my shell script to change and confirm the MAC address for my MacBook. It is running Mac OS 10.13 and seems to work great every time now. I have an alias in my .zshrc for a quick and painless change.
#/bin/zsh
# Changing the wireless MAC in MacOS (X)
sudo /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport –disassociate
echo “Wireless disassociated”
echo “Original MAC address: ” `sudo ifconfig en0 ether | grep ether`
# the first byte of the MAC address has to be an even or the MAC change will fail.
sudo ifconfig en0 ether `openssl rand -hex 6 | sed ‘s/\(..\)/\1:/g; s/.$//’`
echo “new MAC address: ” `sudo ifconfig en0 ether | grep ether`
networksetup -detectnewhardware
echo “MAC changed”
This article proved most useful in the script above, just my little rift on what was on the page.
© 2020, wrightmac. All rights reserved.
No tags for this post.