打开终端,输入两条命令,即可查看当前电脑上所有已保存的wifi以及密码
可以列出已保存的wifi网络名
netsh wlan show profile
打印出WiFi信息(包含密码)
netsh wlan show profile name=Wifi网络名字 key=clear
使用python代码获取
import subprocess
cmd1 = "netsh wlan show profile"
cmd2 = "netsh wlan show profile name={wifi} key=clear"
def get_wifi():
# 执行 查看wifi列表 命令
reslut = subprocess.run(cmd1.split() , capture_output= True,text=True)
if reslut.returncode == 0:
output_lines = reslut.stdout.split("\n")
# 获取到所有wifi的名称
wifi_profiles = [ line.split(":")[1].strip() for line in output_lines if "所有用户配置文件" in line]
for wifi_profile in wifi_profiles:
# 查询每个wifi的密码
cmd = cmd2.replace("{wifi}", wifi_profile)
wifikey = subprocess.run(cmd.split() , capture_output= True,text=True)
if wifikey.returncode == 0:
pwds = [line.split(":")[1].strip() for line in wifikey.stdout.split("\n") if "关键内容" in line]
for pwd in pwds:
print(f'WIFI: {wifi_profile},密码{pwd}')
else:
print(f'WIFI: {wifi_profile} 获取失败')
else:
print("获取WIFI配置失败")
if __name__ == '__main__':
get_wifi()
评论 (0)