分享一个用python写的当地WIFI密码检察器

打印 上一主题 下一主题

主题 577|帖子 577|积分 1731

本章教程,主要分享一个当地wifi密码检察器,用python实现的,感爱好的可以试一试。
  

详细代码

  1. import subprocess  # 导入 subprocess 模块,用于执行系统命令
  2. import tkinter as tk  # 导入 tkinter 模块,用于创建图形用户界面
  3. from tkinter import messagebox, ttk  # 从 tkinter 模块中导入 messagebox 和 ttk 子模块
  4. def get_wifi_passwords():
  5.     """
  6.     获取本地计算机上所有已连接过的 WiFi 配置文件及其密码。
  7.     """
  8.     try:
  9.         # 执行命令获取所有 WiFi 配置文件的列表
  10.         profiles_data = subprocess.check_output(['netsh', 'wlan', 'show', 'profiles']).decode('utf-8', errors='ignore')
  11.         # 解析输出,提取配置文件名称
  12.         profiles = [line.split(':')[1].strip() for line in profiles_data.split('\n') if "All User Profile" in line]
  13.         wifi_passwords = []  # 存储 WiFi 名称和密码的列表
  14.         # 遍历每个配置文件,获取密码
  15.         for profile in profiles:
  16.             profile_info = subprocess.check_output(['netsh', 'wlan', 'show', 'profile', profile, 'key=clear']).decode('utf-8', errors='ignore')
  17.             password_lines = [line.split(':')[1].strip() for line in profile_info.split('\n') if "Key Content" in line]
  18.             password = password_lines[0] if password_lines else "N/A"  # 如果没有密码,则显示 "N/A"
  19.             wifi_passwords.append((profile, password))
  20.         return wifi_passwords
  21.     except Exception as e:
  22.         # 如果发生错误,显示错误信息
  23.         messagebox.showerror("错误", f"发生错误: {str(e)}")
  24.         return []
  25. def copy_password(event):
  26.     """
  27.     复制选中的 WiFi 密码到剪贴板。
  28.     """
  29.     selected_item = tree.selection()[0]
  30.     password = tree.item(selected_item, 'values')[1]
  31.     root.clipboard_clear()
  32.     root.clipboard_append(password)
  33.     messagebox.showinfo("信息", "密码已复制到剪贴板")
  34. def center_window(window, width, height):
  35.     """
  36.     将窗口显示在屏幕中央。
  37.     """
  38.     screen_width = window.winfo_screenwidth()
  39.     screen_height = window.winfo_screenheight()
  40.     x = (screen_width - width) // 2
  41.     y = (screen_height - height) // 2
  42.     window.geometry(f'{width}x{height}+{x}+{y}')
  43. # 创建主窗口
  44. root = tk.Tk()
  45. root.title("WiFi 密码查看器")  # 设置窗口标题
  46. window_width = 400
  47. window_height = 300
  48. root.geometry(f'{window_width}x{window_height}')  # 设置窗口大小
  49. center_window(root, window_width, window_height)  # 窗口居中显示
  50. # 创建表格
  51. tree = ttk.Treeview(root, columns=('SSID', '密码'), show='headings')
  52. tree.heading('SSID', text='WiFi名称', anchor='center')
  53. tree.heading('密码', text='WiFi密码', anchor='center')
  54. tree.column('SSID', anchor='center')
  55. tree.column('密码', anchor='center')
  56. tree.pack(fill=tk.BOTH, expand=True)
  57. # 设置表格样式
  58. style = ttk.Style()
  59. style.configure('Treeview', rowheight=25)
  60. style.configure('Treeview.Heading', font=('Arial', 12, 'bold'))
  61. # 获取 WiFi 密码并显示在表格中
  62. wifi_passwords = get_wifi_passwords()
  63. for wifi, password in wifi_passwords:
  64.     tree.insert('', tk.END, values=(wifi, password))
  65. # 绑定双击事件,双击表格中的一行即可复制密码
  66. tree.bind('<Double-1>', copy_password)
  67. # 启动主事件循环
  68. root.mainloop()
复制代码
  点击wifi名称行,可以快速复制wifi密码到粘贴板上。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

笑看天下无敌手

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表