Python's way of generating random MAC addresses

  • 2020-04-02 14:41:52
  • OfStack

This example shows how python generates random MAC addresses. Share with you for your reference. The specific implementation method is as follows:


#!/usr/bin/python
import random
def randomMAC():
    mac = [ 0x52, 0x54, 0x00,
        random.randint(0x00, 0x7f),
        random.randint(0x00, 0xff),
        random.randint(0x00, 0xff) ]
    return ':'.join(map(lambda x: "%02x" % x, mac))
print randomMAC()

I hope this article has helped you with your Python programming.


Related articles: