【Python小工具】获取本机无线的SSID及对应密码

来源:默认网盘 | 提取码:5dth
  • import subprocess
  • def get_wifi_password():
  • # 执行 netsh wlan show profiles 命令并捕获输出
  • result = subprocess.run(['netsh', 'wlan', 'show', 'profiles'], capture_output=True, text=True)
  • # # 检查命令是否成功执行
  • if result.returncode == 0:
  • # 获取输出信息中的 WiFi 配置文件部分
  • output_lines = result.stdout.split('\n')
  • wifi_profiles = [line.split(":")[1].strip() for line in output_lines if "所有用户配置文件" in line]
  • for profile_name in wifi_profiles:
  • wifikey =subprocess.run(['netsh', 'wlan', 'show', 'profile', 'name=' + profile_name, 'key=clear'], 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'无线SSID:{profile_name},对应密码:{pwd}')
  • with open('pwd.txt','ab+') as f:
  • f.write(f'无线SSID:{profile_name},对应密码:{pwd}\n'.encode())
  • else:
  • print("获取 WiFi 配置信息失败。")
  • else:
  • print("获取 WiFi 配置信息失败。")
  • get_wifi_password()

 

THE END
分享
二维码
打赏
海报
<<上一篇
下一篇>>