Skip to content

Instantly share code, notes, and snippets.

@rixth
Created August 21, 2012 05:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rixth/3412215 to your computer and use it in GitHub Desktop.
Save rixth/3412215 to your computer and use it in GitHub Desktop.
Want to assume a new identity on a network? This function will give you a random (non-multicast) MAC address.
function random-mac() {
local interface="${1:-en0}"
local old_addr=`ifconfig $interface |grep ether|awk '{print $2}'`
local new_addr=`ruby -e "puts ('%02x' % ((rand 64)*4|2))+(0..4).inject('') {|s,x| s + ':%02x' %(rand 256)}"`
`sudo ifconfig $interface ether $new_addr`
if [ $? -eq 0 ]; then
echo "Switched mac address on $interface to $new_addr from $old_addr"
else
echo "FAILED TO SWITCH MAC ADDRRESS ON $interface"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment