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)
 
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)

效果图:

Python显示WiFi密码_第1张图片

你可能感兴趣的:(Python,python,wifi)