Created
August 21, 2012 05:39
-
-
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.
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
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