MAC address generator in python

后端 未结 4 1458
时光说笑
时光说笑 2021-02-15 16:03

For purpose of creating bulk virtual machines, I need to create a random MAC address generator in Python. I don\'t know how to generate random MAC addresses.

Is the foll

4条回答
  •  我在风中等你
    2021-02-15 16:43

    Modified from mamofish's code to Python3:

    mac = '00:00:00:'
    for number in range(16**6):
        hex_num = hex(number)[2:].zfill(6)
        print("{}{}{}:{}{}:{}{}".format(mac,*hex_num))
    

    Generates mac addresses as strings from 00:00:00:00:00:00 to 00:00:00:ff:ff:ff.

提交回复
热议问题