Date created: Monday, October 14, 2019 9:11:37 AM. Last modified: Monday, January 25, 2021 2:10:31 PM

Randomise Wi-Fi MAC

This no longer works on modern OS X:

 

#!/bin/bash

set -e

# Disconnect from any existing network
sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -z

echo "Existing MAC: $(ifconfig en0 | grep ether | awk '{print $NF}')"

# Ensure the first octet is even (unicsat) and not odd (multicast)
o1=$(( (RANDOM % 255) + 1))
while [ $(($o1%2)) -ne 0 ]
do
let o1=$(( (RANDOM % 16) + 1))
done

o2=$(( (RANDOM % 255) + 1))
o3=$(( (RANDOM % 255) + 1))
o4=$(( (RANDOM % 255) + 1))
o5=$(( (RANDOM % 255) + 1))
o6=$(( (RANDOM % 255) + 1))
mac=$(printf "%02x:%02x:%02x:%02x:%02x:%02x" $o1 $o2 $o3 $o4 $o5 $o6)

echo "Trying new MAC: $mac"
sudo ifconfig en0 ether "$mac"
#sudo ifconfig en0 lladdr "$mac"
#networksetup -detectnewhardware

echo "MAC is now: $(ifconfig en0 | grep ether | awk '{print $NF}')"