So I like to set a new, randomly-generated MAC address after every restart using
ruby -e 'print ("%02x"%((rand 64)*4|2))+(0..4).inject(""){|s,x|s+":%02x"%(rand 256)} + "\n"'
and then copy/pasting the output after the command
sudo ifconfig en0 ether
so that I get a new IP address from my ISP each day. I would like to further automate this process so that on startup my computer automatically runs these two commands, but I don't know enough about CLI syntax to make it work. How can I combine these two commands so that ifconfig
takes the generated output of the ruby
command in a single step? And then, how can I get that to automatically run at startup?
Thank you.
Best Answer
Run
EDITOR=nano sudo crontab -e
and add a line like this:@reboot ifconfig en0 ether $(printf \%02x $(($RANDOM\%128*2)))$(head -c4 /dev/random|hexdump -v -e '/1 ":\%02x"')
Commands scheduled by
@reboot
are run after you restart or turn the computer on but not after you log out and back in.%
has to be escaped as\%
in crontab.From a comment at http://osxdaily.com/2010/11/10/random-mac-address-generator/: