Windows10系统使用Python查看本机已存储的WiFi密码
Windows10系统使用Python查看本机已存储的WiFi密码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | import re import subprocess name_list = [] # 定义要执行的命令 command = 'netsh wlan show profiles' # 使用subprocess.run执行命令,并捕获输出 result = subprocess.run(command, shell = True , text = True , stdout = subprocess.PIPE, stderr = subprocess.PIPE) # 检查命令是否执行成功 if result.returncode = = 0 : # 打印命令的输出结果 for line in result.stdout.splitlines(): if '所有用户配置文件' in line: match = re.search(r ':\s*(.*)' , line) wifi_name = match.group( 1 ) # 将获取到的WiFi名称写入存储的目的列表 name_list.append(wifi_name) else : # 如果命令执行失败,打印错误信息 print ( "Error executing command:" , result.stderr) counter_password = 0 counter_open = 0 for info in name_list: if ' ' in info: command_password = f 'netsh wlan show profiles name="{info}" key=clear' else : command_password = f "netsh wlan show profiles {info} key=clear" # 使用subprocess.run执行命令,并捕获输出 result_password = subprocess.run(command_password, shell = True , text = True , stdout = subprocess.PIPE, stderr = subprocess.PIPE) # 检查命令是否执行成功 if result_password.returncode = = 0 : for lines in result_password.stdout.splitlines(): if '关键内容' in lines: matchs = re.search(r ':\s*(.*)' , lines) password_info = matchs.group( 1 ) print (f 'WiFi名称:{info} 的密码是:{password_info}' ) counter_password + = 1 elif '开放式' in lines: print (f 'WiFi名称:{info} 的密码是:开放WiFi,无密码!' ) counter_open + = 1 else : # 如果命令执行失败,打印错误信息 print ( "Error executing command:" , result_password.stderr) print (f '本机已存储的WiFi总数是:{len(name_list)} \n无线WiFi加密的个数是:{counter_password}\n开发WiFi的数量是:{counter_open}' ) |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
2021-12-23 IPv6