MAC address generator script
Todd Zullinger
tmz at pobox.com
Fri Oct 23 22:18:23 UTC 2009
Eugeneapolinary Ju wrote:
> I just can't find a script that generates a valid MAC address :S
>
> Has anyone has one?
There's one in the cobbler source code (which was pulled from xen).
Something like this perhaps:
$ cat /tmp/genmac.py
#!/usr/bin/python
import random
def generate_random_mac():
"""
Generate a random MAC address.
from xend/server/netif.py
Generate a random MAC address.
Uses OUI 00-16-3E, allocated to
Xensource, Inc. Last 3 fields are random.
return: MAC address string
"""
mac = [ 0x00, 0x16, 0x3e,
random.randint(0x00, 0x7f),
random.randint(0x00, 0xff),
random.randint(0x00, 0xff) ]
mac = ':'.join(map(lambda x: "%02x" % x, mac))
return mac
print generate_random_mac()
--
Todd OpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Whenever you find yourself on the side of the majority, it is time to
pause and reflect.
-- Mark Twain
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 542 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/fedora-list/attachments/20091023/2798d3ac/attachment-0001.sig>
More information about the fedora-list
mailing list