当前位置: 首页 > news >正文

分享一个用python写的本地WIFI密码查看器

本章教程,主要分享一个本地wifi密码查看器,用python实现的,感兴趣的可以试一试。

在这里插入图片描述

具体代码

import subprocess  # 导入 subprocess 模块,用于执行系统命令
import tkinter as tk  # 导入 tkinter 模块,用于创建图形用户界面
from tkinter import messagebox, ttk  # 从 tkinter 模块中导入 messagebox 和 ttk 子模块def get_wifi_passwords():"""获取本地计算机上所有已连接过的 WiFi 配置文件及其密码。"""try:# 执行命令获取所有 WiFi 配置文件的列表profiles_data = subprocess.check_output(['netsh', 'wlan', 'show', 'profiles']).decode('utf-8', errors='ignore')# 解析输出,提取配置文件名称profiles = [line.split(':')[1].strip() for line in profiles_data.split('\n') if "All User Profile" in line]wifi_passwords = []  # 存储 WiFi 名称和密码的列表# 遍历每个配置文件,获取密码for profile in profiles:profile_info = subprocess.check_output(['netsh', 'wlan', 'show', 'profile', profile, 'key=clear']).decode('utf-8', errors='ignore')password_lines = [line.split(':')[1].strip() for line in profile_info.split('\n') if "Key Content" in line]password = password_lines[0] if password_lines else "N/A"  # 如果没有密码,则显示 "N/A"wifi_passwords.append((profile, password))return wifi_passwordsexcept Exception as e:# 如果发生错误,显示错误信息messagebox.showerror("错误", f"发生错误: {str(e)}")return []def copy_password(event):"""复制选中的 WiFi 密码到剪贴板。"""selected_item = tree.selection()[0]password = tree.item(selected_item, 'values')[1]root.clipboard_clear()root.clipboard_append(password)messagebox.showinfo("信息", "密码已复制到剪贴板")def center_window(window, width, height):"""将窗口显示在屏幕中央。"""screen_width = window.winfo_screenwidth()screen_height = window.winfo_screenheight()x = (screen_width - width) // 2y = (screen_height - height) // 2window.geometry(f'{width}x{height}+{x}+{y}')# 创建主窗口
root = tk.Tk()
root.title("WiFi 密码查看器")  # 设置窗口标题
window_width = 400
window_height = 300
root.geometry(f'{window_width}x{window_height}')  # 设置窗口大小
center_window(root, window_width, window_height)  # 窗口居中显示# 创建表格
tree = ttk.Treeview(root, columns=('SSID', '密码'), show='headings')
tree.heading('SSID', text='WiFi名称', anchor='center')
tree.heading('密码', text='WiFi密码', anchor='center')
tree.column('SSID', anchor='center')
tree.column('密码', anchor='center')
tree.pack(fill=tk.BOTH, expand=True)# 设置表格样式
style = ttk.Style()
style.configure('Treeview', rowheight=25)
style.configure('Treeview.Heading', font=('Arial', 12, 'bold'))# 获取 WiFi 密码并显示在表格中
wifi_passwords = get_wifi_passwords()
for wifi, password in wifi_passwords:tree.insert('', tk.END, values=(wifi, password))# 绑定双击事件,双击表格中的一行即可复制密码
tree.bind('<Double-1>', copy_password)# 启动主事件循环
root.mainloop()

点击wifi名称行,可以快速复制wifi密码到粘贴板上。

http://www.lryc.cn/news/367405.html

相关文章:

  • 【SkyWalking】启用apm-trace-ignore-plugin追踪忽略插件
  • 独立游戏之路 -- 获取OAID提升广告收益
  • 反转链表 (oj题)
  • Mysql使用中的性能优化——批量插入的规模对比
  • TCP为什么握手是三次,而挥手是四次
  • 前端面试题大合集9----TypeScript
  • Linux:动态库和静态库的编译与使用
  • 【Pyqt6 学习笔记】DIY一个二维码解析生成小工具
  • 关于xilinx srio ip复位问题
  • 04 uboot 编译与调试
  • 【机器学习】机器学习与医疗健康在智能诊疗中的融合应用与性能优化新探索
  • 在线OJ项目测试(selenium+Junit5)
  • 计算机系统基础笔记(12)——控制
  • 使用RedissonClient的管道模式批量查询key
  • UR机器人通信汇总
  • AI学习指南机器学习篇-使用ID3算法构建决策树
  • React实战(一)初始化项目、配置router、redux、axios
  • 高质量 HarmonyOS 权限管控流程
  • java里面封装https请求工具类2
  • 前端面试题日常练-day59 【面试题】
  • 计算机小问题(4)--关闭联想电脑的小组件
  • mac无法读取windows分区怎么办 苹果硬盘怎么读取
  • 【设计模式】JAVA Design Patterns——State(状态模式)
  • Docker搭建可道云
  • 【RISC-V】站在巨人的肩膀上——看开源芯片、软件生态、与先进计算/人工智能/安全的结合
  • test 判断字符串不为空
  • Python数据分析I
  • Qt5/6使用SqlServer用户连接操作SqlServer数据库
  • [经验] 场效应管是如何发挥作用的 #知识分享#学习方法#职场发展
  • 数据挖掘--分类