python寫的本地WIFI密碼查看器的具體代碼
本章教程,主要分享一個本地wifi密碼查看器,用python實現(xiàn)的,感興趣的可以試一試。

具體代碼
import subprocess # 導(dǎo)入 subprocess 模塊,用于執(zhí)行系統(tǒng)命令
import tkinter as tk # 導(dǎo)入 tkinter 模塊,用于創(chuàng)建圖形用戶界面
from tkinter import messagebox, ttk # 從 tkinter 模塊中導(dǎo)入 messagebox 和 ttk 子模塊
def get_wifi_passwords():
"""
獲取本地計算機上所有已連接過的 WiFi 配置文件及其密碼。
"""
try:
# 執(zhí)行命令獲取所有 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_passwords
except Exception as e:
# 如果發(fā)生錯誤,顯示錯誤信息
messagebox.showerror("錯誤", f"發(fā)生錯誤: {str(e)}")
return []
def copy_password(event):
"""
復(fù)制選中的 WiFi 密碼到剪貼板。
"""
selected_item = tree.selection()[0]
password = tree.item(selected_item, 'values')[1]
root.clipboard_clear()
root.clipboard_append(password)
messagebox.showinfo("信息", "密碼已復(fù)制到剪貼板")
def center_window(window, width, height):
"""
將窗口顯示在屏幕中央。
"""
screen_width = window.winfo_screenwidth()
screen_height = window.winfo_screenheight()
x = (screen_width - width) // 2
y = (screen_height - height) // 2
window.geometry(f'{width}x{height}+{x}+{y}')
# 創(chuàng)建主窗口
root = tk.Tk()
root.title("WiFi 密碼查看器") # 設(shè)置窗口標(biāo)題
window_width = 400
window_height = 300
root.geometry(f'{window_width}x{window_height}') # 設(shè)置窗口大小
center_window(root, window_width, window_height) # 窗口居中顯示
# 創(chuàng)建表格
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)
# 設(shè)置表格樣式
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))
# 綁定雙擊事件,雙擊表格中的一行即可復(fù)制密碼
tree.bind('<Double-1>', copy_password)
# 啟動主事件循環(huán)
root.mainloop()點擊wifi名稱行,可以快速復(fù)制wifi密碼到粘貼板上。
到此這篇關(guān)于python寫的本地WIFI密碼查看器的文章就介紹到這了,更多相關(guān)python WIFI密碼查看器內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
基于Python打造三個AI小工具(自動總結(jié)+寫代碼+查資料)的完整指南
這篇文章主要為大家詳細(xì)介紹了如何基于Python打造三個AI小工具,可以實現(xiàn)智能文檔總結(jié)器,AI代碼生成器和智能資料助手,感興趣的小伙伴可以了解下2026-03-03
用Python實現(xiàn)2024年春晚劉謙魔術(shù)
昨晚春晚上劉謙的兩個魔術(shù)表演都非常精彩,忍不住用編程去模擬一下這個過程,所以本文給大家用Python實現(xiàn)2024年春晚劉謙魔術(shù),文中通過代碼示例給大家介紹的非常詳細(xì),需要的朋友可以參考下2024-02-02
python實現(xiàn)提取str字符串/json中多級目錄下的某個值
今天小編就為大家分享一篇python實現(xiàn)提取str字符串/json中多級目錄下的某個值,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-02-02
Python的for和break循環(huán)結(jié)構(gòu)中使用else語句的技巧
平時我們把在if結(jié)構(gòu)中使用else語句當(dāng)作理所當(dāng)然,然而,Python強大的語法糖可以讓else語句在for和while循環(huán)中使用!下面我們就通過例子來看一下Python的for和break循環(huán)結(jié)構(gòu)中使用else語句的技巧2016-05-05
Python實現(xiàn)將通信達.day文件讀取為DataFrame
今天小編就為大家分享一篇Python實現(xiàn)將通信達.day文件讀取為DataFrame,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-12-12

