python完成对本机wifi及密码获取

简单的获取本机电脑以往连接过的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()`

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值