import os
import re
import tkinter as tk
from tkinter import ttk
from ttkbootstrap import Style
name =''
st1=st2=''
aa=gorp=''
v=''
def allwifi():
global name
fp = os.popen('netsh wlan show profiles')
all = fp.read()
aname = re.compile(r':(.*)')
name = aname.findall(str(all))
def view_key(xname):
xname=xname.strip()
global st1,st2
try:
fp=os.popen('netsh wlan show profiles name="{}" key=clear'.format(xname))
all=fp.read()
bb=re.search(r'关键内容 *:(.*)',all)
dd=re.search(r'名称 *:(.*)',all)
st1="wifi名称:{}\nwifi密码:{}".format(dd.group(1),bb.group(1))
except:
st1="该WIFI无密码"
st2 = tk.StringVar()
st2.set(st1)
def xuanze():
global aa,v,name
v=tk.StringVar(window)
v.set("选择你要查看密码的WIFI名称")
om = tk.OptionMenu(window,v,*name).grid(row=0,column=0)
bt=ttk.Button(window,text="查看",style='Primary.TButton',command=wo)
bt.place(x=330,y=0)
def kongjian():
global gorp
gorp=tk.LabelFrame(window,text="WIFI信息",padx=5,pady=5,width=390,height=80,labelanchor='n')
gorp.grid(row=3,padx=5,pady=5)
gorp.grid_propagate(0)
def wo():
view_key(v.get())
gorp.grid_forget()
kongjian()
tk.Label(gorp,textvariable=st2,wraplength=200,justify="left").grid(row=4)
if __name__ == '__main__':
window = tk.Tk()
window.title('Wifi密码查看器')
tk.Label(gorp,text="其实我是一个杀手",wraplength=200,justify="left").grid(row=4)
style = Style(theme='sandstone')
window = style.master
winWidth = 400
winHeight = 160
screenWidth = window.winfo_screenwidth()
screenHeight = window.winfo_screenheight()
x = int((screenWidth - winWidth) / 2)
y = int((screenHeight - winHeight) / 2)
window.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y))
window.attributes('-topmost', -1)
allwifi()
xuanze()
kongjian()
window.mainloop()
|