Script to generate a MAC address
Very simple and useful script to generate a MAC address. Applicable for Docker, Xen, KVM, and other virtual environments.
This Python script produces a random MAC address for guest VMs.
macgen.py
#!/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()
Human Logic, AI Syntax...
Note on Content: I'm a Systems Engineer, not a native English writer. To ensure my technical ideas are clear and accessible, I use AI tools to polish the grammar and style. The workflow is simple: I provide the logic, the code, and the real-world experience. The AI handles the "English-to-Human" translation layer. If you find a bug, that's on me. If you find a perfectly placed comma, that's probably the AI.
Comments
Post a Comment