import uuid import tkinter as tk from tkinter import filedialog as tkFileDialog from tkinter import messagebox def macget(): #获取mac node = uuid.getnode() mac = uuid.UUID(int = node).hex[-12:] return mac def is_number(str1): try: float(str1) return 1 except ValueError: return -1 def plusmac(mac): #字典先行 letterto ={ 'A':10, 'a':10, 'B':11, 'b':11, 'C':12, 'c':12, 'D':13, 'd':13, 'E':14, 'e':14, 'F':15, 'f':15 } numto = { 10:'a', 11:'b', 12:'c', 13:'d', 14:'e', 15:'f', } newmac = [] #读取每一位 ii = 0 while ii < 12: #读取单个,判断是否需要字典 mm = mac[ii] nn = is_number(mm) if nn == 1: #是数字 oo = int(mm) + 3 #判断是否超过10 if oo > 9: newnum = numto[oo] newmac.append(newnum) else: newmac.append(str(oo)) else: oo = letterto[mm] overoo = int(oo) + 3 if overoo < 16: newnum = numto[overoo] newmac.append(str(newnum)) #整个都超了 else: overoveroo = overoo - 16 newmac.append(str(overoveroo)) ii = ii + 1 passmac = ''.join(newmac) return passmac def ordermac(mac): passt = mac[:6] passb = mac[6:12] neworder = [] neworder.append(passb) neworder.append(passt) newpass = ''.join(neworder) return newpass def tuichu(): window.destroy() if __name__ == '__main__': aa = macget() # print (aa) bb = plusmac(aa) # print(bb) cc = ordermac(bb) # print(cc) window = tk.Tk() # 创建窗口对象的背景色 window.title('KEYGEN') # 设置窗口的标题 window.geometry('350x200') # 设置窗口的大小 title = tk.Label(window, text='请使用 Ctrl + C 复制下面的密钥:', font=('微软雅黑', 12), width=25) title.place(x=10,y=10,anchor='nw') path_var1 = tk.StringVar() entry1 = tk.Entry(window, textvariable=path_var1, font=('微软雅黑', 12), width=20, fg ='red') entry1.place(x=10, y=75, anchor='nw') path_var1.set(cc) tk.Button(window,text='关 闭',command=tuichu).place(x=100,y=135,anchor='nw') window.mainloop()