Skip to content

Instantly share code, notes, and snippets.

@pallih
Created January 15, 2014 11:42
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pallih/8434784 to your computer and use it in GitHub Desktop.
Save pallih/8434784 to your computer and use it in GitHub Desktop.
Bash function to randomize MAC address and hostname on OS X. Could live in ~/.bash_profile
function mask(){
# Changes MAC address to a random one and sets the hostname to a random word
# Tested on OS X 10.9 (Macbook Pro)
# Based on http://blog.kejsarmakten.se/all/software/2013/08/30/spoof-mac-on-osx.html
# and http://osxdaily.com/2010/09/06/change-your-mac-hostname-via-terminal/
# Note: neither are permanent (a reboot resets both)
# For a permanent change to hostname: sudo scutil –-set HostName NEWHOST
# Consider using SpoofMAC: https://github.com/feross/SpoofMAC
NEWMAC=$(openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//')
echo "Changing MAC " $(ifconfig en0 | grep ether)
sudo ifconfig en0 ether $NEWMAC
echo "New MAC is:" $(ifconfig en0 | grep ether)
NEWHOST=$(sed `perl -e "print int rand(99999)"`"q;d" /usr/share/dict/words)
echo "Changing hostname: " $(hostname)
sudo hostname $NEWHOST
echo "New hostname is:" $(hostname)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment