19.21. Creating a Script to Generate MAC Addresses

19.21. Creating a Script to Generate MAC Addresses

19.21. Creating a Script to Generate MAC Addresses

Red Hat Virtualization can generate a MAC address for each virtual machine at the time of creation. Since there are 12 million possible numbers on the same subnet is very small, there is a chance you could get the same MAC address. To work around this, you can also write a script to generate a MAC address. This example script contains the parameters to generate a MAC address:

#! /usr/bin/python
# macgen.py script generates a MAC address for Xen guests
#
import random
mac = [ 0x00, 0x16, 0x3e,
random.randint(0x00, 0x7f),
random.randint(0x00, 0xff),
random.randint(0x00, 0xff) ]
print ':'.join(map(lambda x: "%02x" % x, mac))

Generates e.g.:
00:16:3e:66:f5:77
to stdout