赞
踩
使用Tkinter写一款Wifi密码查看小工具,支持Wifi密码的查看以及Wifi信息的导出,简单又实用。
python Tkinter
启动后会读取本机存储的Wifi信息,通过点击对应的Wifi名,即可查看所选wifi的密码。
from tkinter import * from tkinter import ttk from tkinter import messagebox from tkinter.filedialog import * from tkinter.scrolledtext import ScrolledText from Wifi_View_Engine import View_Engine class App: def __init__(self): self.root=Tk() self.root.title('Wifi密码查看') self.root.resizable(0,0) width=380 height=380 left=(self.root.winfo_screenwidth()-width)/2 top=(self.root.winfo_screenheight()-height)/2 self.root.geometry('%dx%d+%d+%d'%(width,height,left,top)) self.e=View_Engine() self.create_widgets() self.set_widgets() self.place_widgets() self.show_local_wifi_infos() self.root.mainloop() def create_widgets(self): self.label1=ttk.Label(self.root,text='本机存储的Wifi:') self.listbox1=Listbox(self.root,justify='center',width=20,height=15) self.label2 = ttk.Label(self.root, text='详细信息:') self.scrolltext = ScrolledText(self.root,width=25, height=21) self.btn_export=ttk.Button(self.root,text='导出',command=self.export_wifi_infos) self.btn_quit=ttk.Button(self.root,text='退出') def set_widgets(self): self.listbox1.bind("<<ListboxSelect>>",self.show_wifi_detail) self.root.protocol("WM_DELETE_WINDOW",self.quit_window) self.btn_quit.config(command=self.quit_window) def place_widgets(self): self.label1.place(x=10,y=5) self.listbox1.place(x=10,y=25,) self.btn_export.place(x=30,y=310) self.label2.place(x=170,y=5) self.scrolltext.place(x=170,y=25,) self.btn_quit.place(x=195,y=310) def show_local_wifi_infos(self): self.all_wifi=self.e.get_wifi_infos() for index,wifi in enumerate(self.all_wifi): self.listbox1.insert(index,wifi) def show_wifi_detail(self,*args): try: current_wifi_name=self.listbox1.get(self.listbox1.curselection()) wifi_password=self.e.get_wifi_pwd(current_wifi_name) if len(wifi_password)!=0: wifi_password=wifi_password[0] else: wifi_password="无密码" self.scrolltext.delete(0.0,END) self.current_wifi_infos=f"Wifi名称:{current_wifi_name}\nWifi密码:{wifi_password}" self.scrolltext.insert(END,self.current_wifi_infos) except TclError: pass def export_wifi_infos(self): try: list_current=self.listbox1.curselection() if len(list_current)!=0: file=asksaveasfilename(initialdir='./',title='请选择',filetypes =[("文本文件",'*.txt')]) if file: with open(file+'.txt' ,mode='a',encoding='utf-8')as f: f.write(self.current_wifi_infos) else: messagebox.showwarning('警告', '请先选择一个Wifi!') except TclError: messagebox.showwarning('警告', '请先选择一个Wifi!') def quit_window(self,*args): ret=messagebox.askyesno('退出','是否要退出?') if ret : self.root.destroy() if __name__ == '__main__': a=App()
# !/usr/bin/env Python # coding=utf-8 import re import os import socket import time import subprocess import win32com.client class View_Engine(object): def do_cmd(self,cmd): """ 执行一个cmd命令 :param cmd: :return: """ res_code=os.system(cmd) return res_code def get_popen_result(self,cmd): """ 执行一串cmd命令获取执行结果 :param cmd: :return: """ find_str = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) execute_result = find_str.stdout.read().decode('gbk',errors='ignore') return execute_result def get_wifi_infos(self): cmd='netsh wlan show profiles' wifi_infos=self.get_popen_result(cmd) wifi=re.findall('所有用户配置文件 : (.*?)\r\n',wifi_infos) return wifi def get_wifi_pwd(self,wifi_name): cmd=f'netsh wlan show profile name="{wifi_name}" key=clear' wifi_detail=self.get_popen_result(cmd) wifi_password=re.findall('关键内容 : (.*?)\r\n',wifi_detail) return wifi_password
本次使用Tkinter制作了一款Wifi密码查看工具,能够查看本机存储的Wifi信息,支持Wifi信息的导出,方便又小巧,程序我打包好放在了蓝奏云大家自取哈~思路、代码方面有什么不足欢迎各位大佬指正、批评!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。