一個用於生成大量mac地址的python指令碼

用户名还没想好發表於2024-05-16

import random


def generate_mac_address():
    mac = [random.choice('0123456789ABCDEF') for _ in range(12)]
    p = 2
    for i in range(5):
        mac.insert(p, '-')
        p += 3
    return ''.join(mac)


num_addresses = 310000

mac_addresses = set()

while len(mac_addresses) < num_addresses:
    mac = generate_mac_address()
    mac_addresses.add(mac)

with open('mac_addresses.csv', 'w') as file:
    for mac in mac_addresses:
        file.write(mac + '\n')

相關文章