DEV Community

Cover image for How to spoof your MAC address on macOS
Dan Curtis
Dan Curtis

Posted on

How to spoof your MAC address on macOS

I upgraded to Monterey recently. For some reason spoofing my MAC address to extend the time on the free WiFi priced into my $5 coffee has become a lot harder.

Before I had one magic ifconfig command to do it, now I have to run four different commands:

Disconnect from the wifi

sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -z
Enter fullscreen mode Exit fullscreen mode

Change my lladdr

My interface is always en0, and I just change the last digit of my MAC address. Holding option while clicking on the wifi menubar tray shows both my interface and MAC address.

sudo ifconfig <interface> lladdr <new MAC address> 
Enter fullscreen mode Exit fullscreen mode

Change my ether

sudo ifconfig <interface> ether <new MAC address> 
Enter fullscreen mode Exit fullscreen mode

Run ifconfig to see if the ether value for my interface changed

ifconfig
Enter fullscreen mode Exit fullscreen mode

Now I can reconnect to my favorite insecure wifi. The wifi menubar tray still shows my old MAC address, but the public network sees the spoofed value from ifconfig.

Top comments (1)

Collapse
 
mikesirs profile image
Mike Sirs
#!/bin/zsh
if [[ $EUID -ne 0 ]]; then
echo "This script must be run with sudo." >&2
exit 1
fi

if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Usage: sudo ./script.sh <interface> <MAC_addr>"
echo "Sets the MAC address for the specified network interface."
echo "Arguments:"
echo " <interface> Network interface to set MAC address for."
echo " <MAC_addr> New MAC address to set."
exit 0
fi

if [[ -z "$1" || -z "$2" ]]; then
echo 'Missing <interface> and/or <MAC_addr>'
echo "Use -h or --help option for usage information."
exit 1
fi

/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -z
ifconfig "$1" lladdr "$2"
ifconfig "$1" ether "$2"
Enter fullscreen mode Exit fullscreen mode