Script to generate a MAC address

Very simple and useful script to generate a MAC address. Applicable for docker, xen, kvm...

#!/usr/bin/python
# macgen.py script to generate a MAC address for guests on Xen

import random

def randomMAC():
    mac = [ 0x00, 0x16, 0x3e,
    random.randint(0x00, 0x7f),
    random.randint(0x00, 0xff),
    random.randint(0x00, 0xff) ]
    return ':'.join(map(lambda x: "%02x" % x, mac))

print randomMAC()

Comments

Popular posts from this blog

FreeRadius and Google Workspace LDAP

pssh (parallel-ssh) problems on Debian 10 with Python 3.7