Changing the Airport MAC address with OS X

Aug 12, 2013 00:00 · 295 words · 2 minute read

If you walk past a fancy-looking bin in the City of London, there’s a chance it may have recorded details of any wifi-enabled devices you happen to be carrying.

Tom Taylor figured out the way that this was being done - the bins are recording the MAC address of the wifi interface, and pointed out that it’s possible to change this if you’re running OS X.

The chances of a bin sniffing the address of a Macbook are fairly slim unless you happen to be using it within wifi range - but there are situations where it’s actually useful to change the address. Tom’s example was reconnecting to time-limited public wifi, but there are plenty of others.

It’s not tricky to do, just fiddly - so here’s a quick-and-dirty script that changes the MAC address of a Macbook’s built-in Airport adaptor to a random value (it assumes that the Airport adaptor is known by the system as eth0, but I’ve never come across a Macbook where that wasn’t the case.)

{% codeblock lang:bash) #!/bin/bash

mac=openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//' echo “Changing Wifi MAC address to $mac”

ifconfig en0 ether $mac

echo “Turning Airport off…” /usr/sbin/networksetup -setairportpower en0 off

sleep 5

echo “Turning Airport on…” /usr/sbin/networksetup -setairportpower en0 on

sleep 5 newmac=ifconfig en0 ether | grep '[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]' newip=ifconfig en0 inet

echo “Airport MAC address: $newmac” echo “Airport IP address: $newip” {% endcodeblock)

To use this, create a text file called or similar (the .sh extension is the important bit) and then make it executable with chmod +x

You can then run it with sudo ./ any time you want to alter the MAC address - the script changes it, then bounces the Airport adaptor to make sure the change takes effect.