硬件厂商MAC地址生成查询器
# 说明在论坛里闲逛的时候突然看到的
[指定硬件厂商MAC地址生成](https://www.52pojie.cn/thread-1353761-1-5.html)
首先还是感谢这位老哥提供的思路以及MAC地址查询网站
(https://standards.ieee.org/products-services/regauth/index.html)
其次还是因为报毒啊,所以不太想用。
自己用Python3写了一个。
这里就直接把代码公开了。毕竟还是别人的想法。
由于读取CSV还是用的遍历形式。启动还是略微有些费时
有更好的办法欢迎提出。
# 使用说明
直接点击选择厂商点击生成即可生成新的MAC地址
也可以复制电脑的MAC地址进行查询
输入框限制了输入内容。非法格式的内容无法输入
# 下载方法
直接用代码自己编译即可。
或者直接从网站下载
# 代码
```
import csv
import random
import pyperclip
from itertools import islice
from tkinter import *
import wx
# -*- coding:utf-8 -*-
macAddlist = []
macManufacturerlist = []
reader = []
'''读取MAC设备文件'''
with open(file="./files/oui.csv",mode="r",encoding='utf-8') as f:
reader = csv.reader(f)
for row in islice(reader,1,None):
macAddlist.append(row)
macManufacturerlist.append(row)
"""
for index in range(len(macAddlist)):
self.SperListView1.Append(,macAddlist])
"""
def FormatMac(inputMAC):
"""
格式化MAC地址
:param inputMAC:
:return: 格式化后的mac地址
"""
if(len(inputMAC.strip()) > 17):
return False
standardMAC = ''
for str in inputMAC:
if(str == ':' or str == '-' or str == '.'):
pass
else:standardMAC += str
return standardMAC.upper()
class Frame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title='MAC地址查询&生成器', size=(580, 300),name='frame',style=541072384)
self.StarWindow = wx.Panel(self)
self.Centre()
self.Edit_MAC = wx.TextCtrl(self.StarWindow,size=(180, 35),pos=(80, 5),value='',name='text',style=0)
self.Edit_MAC.Bind(wx.EVT_TEXT, self.Edit_MAC_nrbgb)
self.Edit_MAC.SetMaxLength(17)
self.LableText1 = wx.StaticText(self.StarWindow,size=(67, 18),pos=(8, 15),label='MAC地址:',name='staticText',
style=2321)
self.BTN_Select = wx.Button(self.StarWindow,size=(80, 35),pos=(270, 5),label='查询',name='button')
self.BTN_Select.Bind(wx.EVT_BUTTON,self.BTN_Select_anbdj)
self.LableText2 = wx.StaticText(self.StarWindow,size=(64, 18),pos=(8, 62),label='生产商:',name='staticText',
style=2321)
self.Edit_Manufacturer = wx.TextCtrl(self.StarWindow,size=(180, 35),pos=(80, 54),value='',name='text',style=16)
self.BTN_Copy = wx.Button(self.StarWindow,size=(80, 35),pos=(269, 54),label='复制',name='button')
self.BTN_Copy.Bind(wx.EVT_BUTTON,self.BTN_Copy_anbdj)
self.SperListView1 = wx.ListCtrl(self.StarWindow,size=(354, 160),pos=(6, 94),name='listCtrl',style=8227)
self.SperListView1.AppendColumn('生产厂商', 0,260)
self.SperListView1.AppendColumn('MAC地址头', 0,89)
for index in range(len(macAddlist)):
self.SperListView1.Append(, macAddlist])
self.BTN_Generate = wx.Button(self.StarWindow,size=(80, 35),pos=(354, 54),label='生成',name='button')
self.BTN_Generate.Bind(wx.EVT_BUTTON,self.BTN_Generate_anbdj)
self.Edit_Lest = wx.TextCtrl(self.StarWindow,size=(100, 35),pos=(449, 7),value='',name='text',style=0)
self.LableText3 = wx.StaticText(self.StarWindow,size=(69, 16),pos=(368, 19),label='MAC尾号:',name='staticText',
style=2321)
self.ComBox1 = wx.ComboBox(self.StarWindow, value=':', pos=(493, 54), name='comboBox', choices=[':', '-', '.'],
style=16)
self.ComBox1.SetSize((57, 31))
self.ComBox1.Bind(wx.EVT_TEXT,self.ComBox1_wbfsbh)
self.Lable4 = wx.StaticText(self.StarWindow, size=(50, 24), pos=(440, 62), label='分隔符:', name='staticText',
style=2321)
def Edit_MAC_nrbgb(self,event):
"""
输入框内容检测
:param event:
:return:
"""
editmac = self.Edit_MAC.GetLineText(0).upper()
for num in range(len(editmac)):
if(ord(editmac) >= ord('0') and ord(editmac) <= ord('F')):
pass
elif(editmac == ':' or editmac == '-' or editmac == '.'):
pass
else:self.Edit_MAC.Remove(num,num+1)
def BTN_Select_anbdj(self,event):
"""
查询厂商信息按钮事件
:param event:
:return:
"""
inputMAC = self.Edit_MAC.GetLineText(0)
isStation = FormatMac(inputMAC)
if(isStation):
macindex = macAddlist.index(isStation[:6])
Manufacturerditel = macManufacturerlist
self.Edit_Manufacturer.Clear()
self.Edit_Lest.Clear()
self.Edit_Manufacturer.AppendText(Manufacturerditel)
self.Edit_Lest.AppendText(isStation.swapcase())
self.SperListView1.Focus(macindex)
self.SperListView1.Select(macindex)
#ListItem1 =self.SperListView1.GetItemText(macindex,col=1)
#print(ListItem1)
def BTN_Generate_anbdj(self,event):
"""
生成新的MAC地址
:param event:
:return:
"""
macindex = self.SperListView1.GetFocusedItem();
inputMAC = self.SperListView1.GetItemText(macindex, col=1)
newMAC= inputMAC + str(hex(random.randint(0x0,0xf)))
for nu in range(5):
newMAC += str(hex(random.randint(0x0, 0xf)))
self.Edit_MAC.Clear()
self.Edit_MAC.AppendText(newMAC)
print(newMAC)
def BTN_Copy_anbdj(self,event):
"""
复制厂商信息
:param event:
:return:
"""
Manufacturer = self.Edit_Manufacturer.GetLineText(0)
if(Manufacturer != ""):
pyperclip.copy(Manufacturer)
def ComBox1_wbfsbh(self,event):
"""
下拉框监听,分隔符修改
:param event:
:return:
"""
inputMAC = self.Edit_MAC.GetLineText(0)
isStation = FormatMac(inputMAC)
stationFGF = self.ComBox1.GetValue()
if (isStation):
if (stationFGF== ".") :staNUM = 4
else:staNUM = 2
self.Edit_MAC.Clear()
StationMac = ''
for Snum in range(len(isStation)):
if (Snum % staNUM == 0 and Snum != 0):
StationMac += stationFGF
StationMac += isStation
self.Edit_MAC.AppendText(StationMac)
#print(StationMac)
class myApp(wx.App):
defOnInit(self):
self.frame = Frame()
self.frame.Show(True)
return True
if __name__ == '__main__':
app = myApp()
app.MainLoop()
``` 点赞大神!消灭零回复 一看代码就醉了。 我的intel wi-fi 6 ax201 160MHz不支持换mac地址,有没有遇到这个问题的
页:
[1]