当前位置:   article > 正文

python3GUI--Wifi密码查看工具(附源码)_gui wifi密码

gui wifi密码


使用Tkinter写一款Wifi密码查看小工具,支持Wifi密码的查看以及Wifi信息的导出,简单又实用。

一.准备工作

python Tkinter

二.预览

1.查看

请添加图片描述
启动后会读取本机存储的Wifi信息,通过点击对应的Wifi名,即可查看所选wifi的密码。

2.导出

请添加图片描述

三.源代码

1.WIfi_Password_View-Gui.py

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()

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86

2.Wifi_View_Engine.py

# !/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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40

四.总结

本次使用Tkinter制作了一款Wifi密码查看工具,能够查看本机存储的Wifi信息,支持Wifi信息的导出,方便又小巧,程序我打包好放在了蓝奏云大家自取哈~思路、代码方面有什么不足欢迎各位大佬指正、批评!
请添加图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/481032
推荐阅读
相关标签
  

闽ICP备14008679号