创建随机mac地址
import random
def randomMAC():
mac = [
random.randint(0x00,0x7f),random.randint(0x00,0xff),0xff)
]
return ':'.join(map(lambda x: "%02x" % x,mac))
print(randomMAC())
创建部分值固定的随机MAC地址
import random
def randomMAC():
mac = [
0x52,0x54,0x00,mac))
print(randomMAC())
创建单播、组播随机mac地址
import random
import subprocess
from subprocess import Popen,PIPE,STDOUT
def randomMAC():
res = "1"
while True:
mac = [
random.randint(0x00,0xff)
]
target_mac = ':'.join(map(lambda x: "%02x" % x,mac))
target_mac_two = target_mac.split(":",1)[0]
target_mac_two = "0x{}".format(target_mac_two)
cmd = "echo $(({}&1))".format(target_mac_two)
proc = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
buff = proc.communicate()[0]
res = buff.split()[0]
if res == "0":
break
return res,target_mac
res,target_mac = randomMAC()
print(res,target_mac)