查看电脑上已连接的wifi以及密码 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()
测试图
|´・ω・)ノヾ(≧∇≦*)ゝ(☆ω☆)(╯‵□′)╯︵┴─┴ ̄﹃ ̄(/ω\)∠( ᐛ 」∠)_(๑•̀ㅁ•́ฅ)→_→୧(๑•̀⌄•́๑)૭٩(ˊᗜˋ*)و(ノ°ο°)ノ(´இ皿இ`)⌇●﹏●⌇(ฅ´ω`ฅ)(╯°A°)╯︵○○○φ( ̄∇ ̄o)ヾ(´・ ・`。)ノ( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃(ó﹏ò。)Σ(っ °Д °;)っ( ,,´・ω・)ノ╮(╯▽╰)╭ o(*////▽////*)q >﹏<( ๑´•ω•) (。•ˇ‸ˇ•。)
|´・ω・)ノヾ(≧∇≦*)ゝ(☆ω☆)(╯‵□′)╯︵┴─┴ ̄﹃ ̄(/ω\)∠( ᐛ 」∠)_(๑•̀ㅁ•́ฅ)→_→୧(๑•̀⌄•́๑)૭٩(ˊᗜˋ*)و(ノ°ο°)ノ(´இ皿இ`)⌇●﹏●⌇(ฅ´ω`ฅ)(╯°A°)╯︵○○○φ( ̄∇ ̄o)ヾ(´・ ・`。)ノ( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃(ó﹏ò。)Σ(っ °Д °;)っ( ,,´・ω・)ノ╮(╯▽╰)╭ o(*////▽////*)q >﹏<( ๑´•ω•) (。•ˇ‸ˇ•。)
|´・ω・)ノヾ(≧∇≦*)ゝ(☆ω☆)(╯‵□′)╯︵┴─┴ ̄﹃ ̄(/ω\)∠( ᐛ 」∠)_(๑•̀ㅁ•́ฅ)→_→୧(๑•̀⌄•́๑)૭٩(ˊᗜˋ*)و(ノ°ο°)ノ(´இ皿இ`)⌇●﹏●⌇(ฅ´ω`ฅ)(╯°A°)╯︵○○○φ( ̄∇ ̄o)ヾ(´・ ・`。)ノ( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃(ó﹏ò。)Σ(っ °Д °;)っ( ,,´・ω・)ノ╮(╯▽╰)╭ o(*////▽////*)q >﹏<( ๑´•ω•) (。•ˇ‸ˇ•。)
555