Python生成隨機MAC地址
更新時間:2015年03月10日 11:29:25 投稿:hebedich
這篇文章主要介紹了Python生成隨機MAC地址的相關資料,需要的朋友可以參考下
利用python代碼生成一個隨機的MAC地址,使用python網(wǎng)絡編程時或可用上,如果使用scapy模塊則可直接利用RandMAC()函數(shù)來生成MAC。
python
復制代碼 代碼如下:
import random
Maclist = []
for i in range(1,7):
RANDSTR = "".join(random.sample("0123456789abcdef",2))
Maclist.append(RANDSTR)
RANDMAC = ":".join(Maclist)
print RANDMAC
--------------------------------運行結果-----------------------------------
e4:13:0e:1a:73:f5
下列的Fake_HW是用struct打包成二進制格式的mac地址
復制代碼 代碼如下:
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
--------------------結果-----------------------------
24:c7:6f:92:2c:42
以上就是本文的全部內容了,希望大家能夠喜歡。
您可能感興趣的文章:
- 用python查找統(tǒng)一局域網(wǎng)下ip對應的mac地址
- Python3獲取電腦IP、主機名、Mac地址的方法示例
- python獲取本機mac地址和ip地址的方法
- python生成隨機mac地址的方法
- python通過scapy獲取局域網(wǎng)所有主機mac地址示例
- python3判斷IP地址的方法
- python IP地址轉整數(shù)
- python 輸入字符串生成所有有效的IP地址(LeetCode 93號題)
- 基于python實現(xiàn)查詢ip地址來源
- python如何判斷IP地址合法性
- Python中IP地址處理IPy模塊的方法
- 如何用Python獲取計算機名,ip地址,mac地址
相關文章
Python Django基礎二之URL路由系統(tǒng)
這篇文章主要介紹了Python Django基礎二之URL路由系統(tǒng) 的相關資料,需要的朋友可以參考下2019-07-07

