projectz

Tech, Gadgets, Photography, Social Media and Poor Spelling

Generate and Set a Random Valid MAC Address from the Command Line in OS X

Generate and Set a Random Valid MAC Address from the Command Line in OS X
Generate and set random MAC address in OS X

We’ve shown you how to generate MAC addresses randomly and then how to go about changing a MAC address in OS X Lion and OS X Mountain Lion, but why have those be two separate actions? Using the command line, you can combine the two events into a single action to generate a valid MAC and then set it immediately.

Launch the Terminal and paste the following onto a single line:

openssl rand -hex 1 | tr '[:lower:]' '[:upper:]' | xargs echo "obase=2;ibase=16;" | bc | cut -c1-6 | sed 's/$/00/' | xargs echo "obase=16;ibase=2;" | bc | sed "s/$/:$(openssl rand -hex 5 | sed 's/(..)/1:/g; s/.$//' | tr '[:lower:]' '[:upper:]')/" | xargs sudo ifconfig en0 ether

There is no confirmation or output, the MAC address is set immediately which you can verify with the following command:

ifconfig en0 |grep ether

You will probably need to reconnect to the wireless router after issuing the command, and in some cases turn wi-fi on and off again.

If you intend on using this often, setting up an alias in .bash_profile would be a good idea to avoid having to cut and paste the massive block of text.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Information

This entry was posted on May 5, 2012 by in link and tagged , , , , .
%d bloggers like this: