欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python寫的本地WIFI密碼查看器的具體代碼

 更新時(shí)間:2024年06月11日 09:24:09   作者:Roc-xb  
本文主要分享一個本地wifi密碼查看器,用python實(shí)現(xiàn)的,代碼簡單易懂,感興趣的朋友跟隨小編一起看看吧

本章教程,主要分享一個本地wifi密碼查看器,用python實(shí)現(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():
    """
    獲取本地計(jì)算機(jī)上所有已連接過的 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()

點(diǎn)擊wifi名稱行,可以快速復(fù)制wifi密碼到粘貼板上。

到此這篇關(guān)于python寫的本地WIFI密碼查看器的文章就介紹到這了,更多相關(guān)python WIFI密碼查看器內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論