(命令行窗口下)输入命令便可以查看我们连接过的WIFI名称
netsh wlan show profiles
输入netsh wlan show profiles (要查询的wifi名称) key=clear ,即可查看相应WiFi的连接密码。
netsh wlan show profile name='nova 6 SE' key=clear
使用python获取连接的wifi密码
import subprocess
# 执行netsh命令获取Wi-Fi密码
result = subprocess.check_output('netsh wlan show profiles', shell=True).decode('gbk')
# 解析结果获取Wi-Fi配置文件名称
profiles = [line.split(':')[1].strip() for line in result.split('\n') if '所有用户配置文件 :' in line]
# 查询每个Wi-Fi配置文件的密码并保存到文件
with open('WiFi.txt', 'w') as f:
for profile in profiles:
try:
password_result = subprocess.check_output(f'netsh wlan show profile name='{profile}' key=clear', shell=True).decode('gbk')
password = [line.split(':')[1].strip() for line in password_result.split('\n') if '关键内容' in line][0]
f.write(f'{profile}密码为:【{password}】\n')
print(f'{profile}密码为:【{password}】')
except:
print(f'无法获取{profile}的密码')
print('查询结果已保存在WiFi.txt文件中')
input('按任意键退出查询')
使用Python来获取Wi-Fi密码并保存到文件中的操作。首先,它使用subprocess
模块执行netsh wlan show profiles
命令来获取Wi-Fi配置文件的列表。然后,通过解析命令输出,提取出每个配置文件的名称。接下来,它循环遍历每个配置文件,使用netsh wlan show profile
命令查询该配置文件的密码,并将结果保存到文件中。最后,打印出每个配置文件的密码,并将查询结果保存在WiFi.txt
文件中。如果无法获取某个配置文件的密码,会打印相应的提示信息。
运行效果:
联系客服