this post was submitted on 23 Aug 2023
905 points (98.6% liked)

Programmer Humor

19463 readers
30 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] kool_newt@lemm.ee 2 points 1 year ago* (last edited 1 year ago)

I use this to make MACs for my VMs and virtual NICs. The 00:16:3E prefix means it's Xen virtualization, so change this part as needed.

#!/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())

Use

$ macgen.py 
00:16:3e:17:ed:b1