吧唧吧唧的吃. . . . . . . . .

python查看WiFi密码


python查看WiFi密码

from os import popen
from re import search, findall
from time import sleep
 
def show_saved():
    s = popen('netsh wlan show profiles').read()
    ssids = findall(r'所有用户配置文件 : (.*)\n', s)
    return ssids
def show_pwd(ssid):
    s = popen(f'netsh wlan show profiles "{ssid}" key=clear').read()
    try: pwd = search(r'关键内容( *): (.*)', s).groups()[1]
    except: pwd = 'NOT FOUND!'
    # return pwd
    print(ssid+"的密码是:"+pwd)
    print()
    print()
 
if __name__ == '__main__':
    print('Input ssid to show its password, or input "/exit" to exit.\n')
    print('All saved wifi ssids: ')
    ssids = show_saved()
    print("》》所有wifi密码列表:《《")
    for ssid in ssids: 
        print('  ' + ssid)
        show_pwd(ssid)
    # while True:
    #     query = input('>')
    #     if query == '/exit': break
    #     print(show_pwd(query))
    # print('Exit...')
    # sleep(0.3)

import subprocess

# 获取wifi列表
output = subprocess.run(['netsh','wlan','show','profiles'],capture_output = True).stdout.decode('gbk').split('\n')
wifis = [line.split(':')[1][1:-1] for line in output if "所有用户配置文件" in line]

#查看每个wifi对应的密码
for wifi in wifis:
    results = subprocess.run(['netsh','wlan','show','profile',wifi,'key=clear'],capture_output = True).stdout.decode('gbk',errors = 'ignore').split('\n')
    results = [line.split(':')[1][1:-1] for line in results if "关键内容" in line]
    try:
        print(f'wifi名:{wifi},密码:{results[0]}')
    except IndexError:
        print(f'wifi名:{wifi},密码:无法提取')

文章作者: 668rose
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 668rose !
评论
  目录