Pages

Sunday, January 26, 2014

Generate random MAC Address with bash on Linux

Generate random MAC Address with bash on Linux 

 MACAddress=$(dd if=/dev/urandom bs=1024 count=1 2>/dev/null|md5sum|sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*$/00:\2:\3:\4:\5:\6/')

echo $MACAddress

Reference:
http://makingtechnologyeasier.blogspot.in/2013/08/generate-random-mac-address-with-bash.html

2 comments:

  1. There is a bit easier variant.

    longer:

    openssl rand -hex 6 | sed 's/\(..\)\(..\)\(..\)\(..\)\(..\)\(..\)/\1:\2:\3:\4:\5:\6/'

    or shorter:

    openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/:$//'

    The load consumption of both variants is very similar according to quick measuring with time.

    ReplyDelete