Skip to content

Instantly share code, notes, and snippets.

@perks
Created June 12, 2014 01:05
Show Gist options
  • Save perks/aab7ac4e6635affb28b4 to your computer and use it in GitHub Desktop.
Save perks/aab7ac4e6635affb28b4 to your computer and use it in GitHub Desktop.
Randomize Mac Address if not connected to Wi-Fi (OSX)
#!/bin/bash
INTERFACE=en0
OUI="/opt/local/etc/oui.txt"
OUI_LEN=19004
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`
CMD="$CMD$C"
if [ $((i % 2)) = 0 ] && [ $i != 6 ]; then
CMD="$CMD:"
fi
done
RESULT=`$CMD`
echo $CMD
fi
sleep 30
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment