【编程】 python 读取WIFI密码

WIFI密码忘记了怎么办

电脑上会保存已经连接过的WIFI密码,通过该原理,可以查看连接过的WIFI密码

工具原理

使用命令行工具 netsh wlan show profiles 来列出所有保存的Wi-Fi配置文件。对于每个配置文件,通过命令

netsh wlan show profile name=[name] key=clear 来获取密码(如果存在)。输出每个Wi-Fi网络的名字及其对应的密码。

第一步 新建py文件

新建txt文件,将名字改为 wifipwd.py,复制以下内容,粘贴到 wifipwd.py文件中保存

第二步 运行python

在文件夹地址栏输入 cmd 回车,在cmd中输入 python wifipwd.py 运行看结果

C:\Users\18K.ICU\Desktop\>python wifipwd.py
WI-FI SSID: 18K-5G       Password: 18K18K520
WI-FI SSID: 18K.ICU-5G   Password: 18k.icu
WI-FI SSID: CCTV-5G      Password: 18K.ICU
WI-FI SSID: TEST_5G      Password: 18K18K88
python代码
import subprocess
import re
# www.18k.icu
def get_wifi_profiles():
    try:
        command = r"netsh wlan show profiles"
        networks = subprocess.check_output(command, shell=True).decode('gbk', errors='ignore')
        wifi_names = re.findall(r":\s*(.+)", networks)
        return [name.strip() for name in wifi_names if "组策略配置文件" not in name]
    except subprocess.CalledProcessError as e:
        print(f"Error executing command: {e}")
        return []

def get_wifi_password(wifi_name):
    try:
        command = f'netsh wlan show profile name="{wifi_name}" key=clear'
        result = subprocess.check_output(command, shell=True).decode('gbk', errors='ignore')
        password = re.search(r"关键内容\s*:\s*(.*)|Key Content\s*:\s*(.*)", result)
        return password.group(1).strip() if password else None
    except subprocess.CalledProcessError as e:
        print(f"Error executing command for {wifi_name}: {e}")
        return None

def main():
    wifi_profiles = get_wifi_profiles()
    if not wifi_profiles:
        print("No Wi-Fi configurations found.")
        return
    for wifi in wifi_profiles:
        password = get_wifi_password(wifi)
        if password:
            print(f"WI-FI SSID: {wifi}\tPassword: {password}")
        else:
            print(f"Wi-Fi SSID: {wifi}\tPassword: ")

if __name__ == "__main__":
    main()

下载代码

https://www.18k.icu/code/python/wifipwd.py

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值