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