Jump to content

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


Recommended Posts

Posted

<div class="KonaBody"><p><img src="http://cdn.osxdaily.com/wp-content/uploads/2012/05/change-mac-address-os-x.jpg" alt="Generate and set random MAC address in OS X " title="change-mac-address-os-x" width="620" height="152" class="aligncenter size-full wp-image-29832" /></p>

<p>We’ve shown you how to <a href="http://osxdaily.com/2010/11/10/random-mac-address-generator/">generate MAC addresses randomly</a> and then how to go about <a href="http://osxdaily.com/2012/03/01/change-mac-address-os-x/">changing a MAC address in OS X</a> 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.</p>

<p>Launch the Terminal and paste the following onto a single line:</p>

<p><code>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</code></p>

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

<p><code>ifconfig en0 |grep ether</code></p>

<p>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.</p>

<p>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.</p>

<p><em>Thanks to <a href="http://osxdaily.com/2012/03/01/change-mac-address-os-x/#comment-384258">osmium</a> for the great tip</em></p>

</div>

<p><a href="http://feedads.g.doubleclick.net/~a/Z8l8rH6hHQY8Vye6E62pcqejIXk/0/da"><img src="http://feedads.g.doubleclick.net/~a/Z8l8rH6hHQY8Vye6E62pcqejIXk/0/di" border="0" ismap="true"></img></a><br/>

<a href="http://feedads.g.doubleclick.net/~a/Z8l8rH6hHQY8Vye6E62pcqejIXk/1/da"><img src="http://feedads.g.doubleclick.net/~a/Z8l8rH6hHQY8Vye6E62pcqejIXk/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">

<a href="http://feeds.feedburner.com/~ff/osxdaily?a=35nTuhp5fvA:gcsm3yVJX7c:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/osxdaily?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=35nTuhp5fvA:gcsm3yVJX7c:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/osxdaily?i=35nTuhp5fvA:gcsm3yVJX7c:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=35nTuhp5fvA:gcsm3yVJX7c:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/osxdaily?i=35nTuhp5fvA:gcsm3yVJX7c:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=35nTuhp5fvA:gcsm3yVJX7c:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/osxdaily?d=7Q72WNTAKBA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/osxdaily?a=35nTuhp5fvA:gcsm3yVJX7c:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/osxdaily?d=qj6IDK7rITs" border="0"></img></a>

</div><img src="http://feeds.feedburner.com/~r/osxdaily/~4/35nTuhp5fvA" height="1" width="1"/>

 

View the full article

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days


×
×
  • Create New...