`python实现Mac地址生成器`
蓝牙MAC地址生成器
本程序使用python生成了一个产生mac地址的小脚本,可以按照要求在后四位生成指定序列的N个mac序列,为一些场景生成二维码提供准备。程序比较简单,并且仅适用于特地场景,仅供参考。
使用tkinter搭建的界面,代码如下
// An highlighted block
import tkinter as tk
from tkinter import simpledialog
mac = 'DD:DC:DB:DA:00:00'
num = 100
def input_str():
global mac
r = simpledialog.askstring('MAC地址', '请输入起始的MAC地址', initialvalue='DD:DC:DB:DA:00:00')
if r:
print(r)
mac = r
def input_int():
global num
r = simpledialog.askinteger('数量录入', '请输入整数', initialvalue=100)
if r:
print(r)
num = r
def make_code(mac,num):
filename = 'MAC.txt'
fs_list = []
x = 0
y = 0
if mac[12:14] != '00':
x = int(mac[12:14],16)
if mac[15:17] != '00':
y = int(mac[15:17],16)
print(x,y)
num_pre = 256 * x + y
print (num_pre)
num_aft = num_pre + num
print("%04X"%num_aft)
try:
fs_list.append(open(filename, 'w', encoding='utf-8'))
for number0 in range(num_pre, num_aft):
fs_list[0].write('DD:DC:DB:DA:'+str("%04X" % number0)[0:2] + ':' +str("%04X" % number0)[2:4] + '\n')
except IOError as ex:
print(ex)
print('写文件时发生错误!')
finally:
for fs in fs_list:
fs.close()
tk.messagebox.showinfo('提示','生成完毕')
def main():
root = tk.Tk()
root.title('MAC地址生成器_lettern')
root.geometry('300x100+300+300')
label = tk.Label(root, text='请输入起始的MAC地址和生成的数量', font='宋体 -14', pady=8)
label.pack()
frm = tk.Frame(root)
btn_str = tk.Button(frm, text=' 起始MAC地址 ', width=14, command=input_str)
btn_str.pack(side=tk.LEFT)
btn_int = tk.Button(frm, text=' 生成个数 ', width=10, command=input_int)
btn_int.pack(side=tk.LEFT)
btn_int = tk.Button(frm, text='开始生成', width=8, command=lambda :make_code(mac,num))
btn_int.pack(side=tk.RIGHT)
frm.pack()
root.mainloop()
if __name__ == '__main__':
main()