Python 创建随机mac地址(单播、组播)
生活随笔
收集整理的這篇文章主要介紹了
Python 创建随机mac地址(单播、组播)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
創建隨機mac地址
import random def randomMAC(): mac = [ random.randint(0x00, 0x7f), random.randint(0x00, 0x7f), random.randint(0x00, 0x7f), random.randint(0x00, 0x7f), random.randint(0x00, 0xff), random.randint(0x00, 0xff)]return ':'.join(map(lambda x: "%02x" % x, mac))print(randomMAC())創建部分值固定的隨機MAC地址
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())創建單播、組播隨機mac地址
import random import subprocess from subprocess import Popen, PIPE, STDOUTdef randomMAC():res = "1"while True:mac = [ random.randint(0x00, 0x7f), random.randint(0x00, 0x7f), random.randint(0x00, 0x7f), random.randint(0x00, 0x7f), random.randint(0x00, 0xff), 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":breakreturn res, target_macres, target_mac = randomMAC() print(res, target_mac)總結
以上是生活随笔為你收集整理的Python 创建随机mac地址(单播、组播)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在URL上设置时间戳
- 下一篇: poj1852