index rss mastodon twitter github linkedin email
Álvaro Ramírez
sponsor

Álvaro Ramírez

15 February 2016 Generating a random MAC address

As some point I had to generate a random MAC address. This is the snippet I used:

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 'MAC => %s' % randomMAC()
MAC => 00:16:3e:7e:f7:fa