MAC Randomizer: Counter WiFi Tracking/Spying

After reading one of many that simply track your MAC address around town, I thought a little bit more security was appropriate. Your MAC address can be tracked regardless of whether or not you actually connect to a WiFi network, as your laptop is almost always scanning for nearby WiFi access points.

Below is a simple bash script I wrote that runs on OSX (and can be easily adapted to other OS’s) that will randomize your MAC address every 30 seconds, and help prevent MAC-based tracking such as what the NSA and friends are testing out. It only does this if you’re not currently connected to a WiFi access point, otherwise your connection would get reset. Copy this somewhere and run it as root when you log in.

NOTE: You’ll need to download this file and put it into /opt/local/etc/oui.txt.



while [ true ]; do
    STATUS=`ifconfig ${INTERFACE} | grep status: | awk '{print $2}'`
    if [ "$STATUS" = "inactive" ]; then
        R=$(((RANDOM % ${OUI_LEN})+1))
        PREFIX=`head -$R $OUI | tail -1`
        CMD="sudo ifconfig ${INTERFACE} ether ${PREFIX}:"
        for i in `seq 1 6`; do
            R=$(((RANDOM % 15)+1))
            C=`echo "obase=16; $R" | bc`
            if [ $((i % 2)) = 0 ] && [ $i != 6 ]; then
        echo $CMD
    sleep 30

You can have this script automatically run at system boot by creating a simple launch script at /Library/LaunchDaemons/com.zdziarski.macrandomize.plist. This will run it in the background, and will also randomize your MAC every time you boot your computer.

NOTE: You might want to turn this off when paying for hotel or airport WiFi, until you’re finished with your session.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">