Created
June 12, 2014 01:05
-
-
Save perks/aab7ac4e6635affb28b4 to your computer and use it in GitHub Desktop.
Randomize Mac Address if not connected to Wi-Fi (OSX)
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 | |
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