简单的获取本机电脑以往连接过的wifi及其密码
`import os
import xml.etree.ElementTree as ET
import tkinter as tk
from tkinter import *
import easygui
icount=0
def Wifiget():
spath=easygui.diropenbox()
spath=spath+’\’
worder=“netsh wlan export profile folder=”+spath+" key=clear"
os.system(worder)
savem=[]
saven=[]
WIFIcount=0
mpan=0
file_name=os.listdir(spath)
for File in file_name:
WIFIcount=WIFIcount+1
File=spath+File
tree=ET.ElementTree(file=File)
root=tree.getroot()
count=0
for j in tree.iter():
a,b=j.tag.split(’}’)
if(b==“sharedKey”):
mpan=1
break
if(mpan0):
savem.append(“无密码”)
for i in tree.iter():
#print(i.tag,i.text)
a,b=i.tag.split(’}’)
if(b’name’):
count=count+1
if(count<2):
saven.append(i.text)
if(b==“keyMaterial”):
savem.append(i.text)
mpan=0
spath=spath+“wifi.txt”
f=open(spath,“w”)
with f:
for i in range(len(saven)):
f.write(“wifi名:”+saven[i]+" “)
f.write(“password:”+savem[i]+”\n")
for i in range(len(saven)):
e.insert(i+1.0,“wifi名:{0} password:{1}”.format(saven[i],savem[i])+’\n’)
e.insert(i+2.0,“wifi文件写入成功\n”)
e.insert(i+3.0,“wifi个数:{0}”.format(WIFIcount)+’\n’)
icount=i
def readxml(e1):
path=easygui.fileopenbox(default=’*.xml’)
tree1=ET.ElementTree(file=path)
root1=tree1.getroot()
i=0
for j in tree1.iter():
e1.insert(i+1.0,str(j.tag)+" "+str(j.text)+’\n’)
def create():
top = Toplevel()
top.title(‘Python’)
top.geometry(‘1068x681+10+10’)
s2 = tk.Scrollbar(root)
e1=Text(master=top,height=200,width=100,yscrollcommand=s2.set)
s2.pack(side=tk.RIGHT,fill=tk.Y)
s2.config(command=e.yview)
e1.pack(side=‘left’)
Button(top, text=‘选择配置文件’,width=10,height=2,command=readxml(e1)).pack()
if name ==‘main’:
root=tk.Tk(className=‘wifi获取’)
root.geometry(‘1068x681+10+10’)
s1 = tk.Scrollbar(root)
e=Text(master=root,height=200,width=100,yscrollcommand=s1.set)
s1.pack(side=tk.RIGHT,fill=tk.Y)
s1.config(command=e.yview)
e.pack(side = LEFT)
button=Button(master=root,text=‘选择路径’,width = 10,height =2,command=Wifiget).pack()
button2=Button(master=root,text=‘查看配置’,width=10,height=2,command=create).pack()
root.mainloop()`