Last active
August 29, 2015 13:55
-
-
Save mislav/8724668 to your computer and use it in GitHub Desktop.
Randomize MAC address (e.g. unlimited wifi access on airports)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
current_mac() { | |
ifconfig en0 ether | awk '/ether / { print $2 }' | |
} | |
current_mac_wifi() { | |
networksetup -getmacaddress Wi-Fi | awk '{ print $3 }' | |
} | |
random_mac() { | |
openssl rand -hex 6 | sed "s/\(..\)/\1:/g; s/:$//" | |
} | |
assign_mac() { | |
sudo ifconfig en0 ether "$1" | |
} | |
randomize() { | |
old_mac="$(current_mac)" | |
echo "previous MAC address: ${old_mac}" | |
# The first byte of a host MAC address must be even | |
while [ "$old_mac" = "$(current_mac)" ]; do | |
assign_mac "$(random_mac)" | |
sleep 0.1 | |
done | |
echo "new MAC address: $(current_mac)" | |
} | |
networksetup -setairportpower en0 on | |
sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -z | |
if [ -n "$1" ]; then | |
assign_mac "$1" | |
echo "new MAC address: $(current_mac)" | |
else | |
randomize | |
fi | |
sudo networksetup -detectnewhardware | |
echo "Wi-Fi MAC address: $(current_mac_wifi)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment