Skip to content

Instantly share code, notes, and snippets.

@tel
Created June 30, 2012 18:34
Show Gist options
  • Save tel/3024994 to your computer and use it in GitHub Desktop.
Save tel/3024994 to your computer and use it in GitHub Desktop.
Mac Address Spoofing Script
#!/usr/bin/env sh
SCRIPT=`basename $0`
BACKUP=$HOME/.mac.orig
case "$1" in
current)
ifconfig en0 | ack ether | cut -d\ -f 2
;;
new)
openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'
;;
set)
ifconfig en0 ether $2
;;
spoof)
if [ ! -f $BACKUP ]
then
CURR=`$0 current`
echo $CURR > ~/.mac.orig
echo Backed up original address: $CURR
fi
NEW=`$0 new`
echo Setting to $NEW
`$0 set $NEW` && echo Set.
;;
unspoof)
if [ -f $BACKUP ]
then
OLD=`cat ~/.mac.orig`
echo Restoring to $OLD
`$0 set $OLD` && echo Restored.
else
echo File $BACKUP does not exist; cannot restore!
exit 1
fi
;;
*)
echo "Usage: $SCRIPT { current | new | set [ADDRESS] | spoof | unspoof }"
echo "Current is $($0 current)"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment