This article describes how to generate random MAC addresses in Python. For more information, see use python code to generate a random MAC address, if you use the scapy module, you can directly use the RandMAC () function to generate a MAC.
Python
The code is as follows:
Import random
Maclist = []
For I in range (1, 7 ):
RANDSTR = "". join (random. sample ("0123456789 abcdef", 2 ))
Maclist. append (RANDSTR)
RANDMAC = ":". join (Maclist)
Print RANDMAC
-------------------------------- Running result -----------------------------------
E4: 13: 0e: 1a: 73: f5
The following Fake_HW is a mac address packaged in binary format using struct.
The code is as follows:
Import random
Import struct
Mac_bin_list = []
Mac_hex_list = []
For I in range (1, 7 ):
I = random. randint (0x00, 0xff)
Mac_bin_list.append (I)
Fake_HW = struct. pack ("BBBBBB", mac_bin_list [0], mac_bin_list [1], mac_bin_list [2], mac_bin_list [3], mac_bin_list [4], mac_bin_list [5]
For j in mac_bin_list:
Mac_hex_list.append (hex (j ))
Hardware = ":". join (mac_hex_list). replace ("0x ","")
Print Hardware
-------------------- Result -----------------------------
24: c7: 6f: 92: 2c: 42
The above is all the content of this article. I hope you will like it.