网站首页 > 技术文章 正文
学习python练手,脚本方便获取电脑里存储过的所有WiFi密码,其原理是自动化"netsh wlan show profiles"的查询过程,后通过正则匹配获取
私信小编01即可获取python学习资源
# subprocess 模块允许我们启动一个新进程,并连接到它们的输入/输出/错误管道,从而获取返回值
import subprocess
import re
# 用于判断OS的语言
import locale
loc_lang = locale.getdefaultlocale()
# print(loc_lang[0])
# 代码中用到的正则匹配模式字符串,提取出来以便不同语言系统使用,默认支持中文英文,其他语言需要更改匹配语句
if loc_lang[0] == "zh_CN":
re_pattern = ["所有用户配置文件 : (.*)\r", "安全密钥 : 不存在", "关键内容 : (.*)\r"]
else:
re_pattern = ["All User Profile : (.*)\r", "Security key : Absent", "Key Content : (.*)\r"]
# 如果 capture_output 设为 true,stdout 和 stderr 将会被捕获
cmd_output = subprocess.run(["netsh", "wlan", "show", "profiles"], capture_output=True).stdout.decode('gbk')
# print(cmd_output)
wifi_names = (re.findall(re_pattern[0], cmd_output))
# print(wifi_names)
wifi_list = []
if len(wifi_names) != 0:
for name in wifi_names:
# 每一个wifi的信息存储在一个字典里
wifi_profile = {}
profile_info = subprocess.run(["netsh", "wlan", "show", "profiles", name],
capture_output=True).stdout.decode('gbk')
# print(profile_info)
# 判断wifi密码是否存储在windows计算机里,不存在则忽略
if re.search(re_pattern[1], profile_info):
continue
else:
wifi_profile["ssid"] = name
# 密码存在时,加上命令参数“key=clear”显示wifi密码
profile_info_pass = subprocess.run(["netsh", "wlan", "show", "profiles", name, "key=clear"],
capture_output=True).stdout.decode('gbk')
password = re.search(re_pattern[2], profile_info_pass)
# print(password)
if not password:
wifi_profile["password"] = None
else:
wifi_profile["password"] = password[1]
wifi_list.append(wifi_profile)
for i in range(len(wifi_list)):
print(wifi_list[i])
结果
- 上一篇: 电脑找回WIFI密码
- 下一篇: 教你两步查看别人的wifi密码
猜你喜欢
- 2024-11-26 Win7\8\10下一条cmd命令可查得笔记本电脑连接过的Wifi密码
- 2024-11-26 一文搞懂MySQL行锁、表锁、间隙锁详解
- 2024-11-26 电脑的wifi密码忘记了?一招教你如何找回密码,简单明了,快收藏
- 2024-11-26 代码解决忘记密码问题 教你用CMD命令查看所有连接过的WIFI密码
- 2024-11-26 CMD命令提示符能干嘛?这些功能你都知道吗?
- 2024-11-26 性能测试之慢sql分析
- 2024-11-26 论渗透信息收集的重要性
- 2024-11-26 如何查看电脑连接过的所有WiFi密码
- 2024-11-26 详解mysql数据库性能优化实验--从两个sql来体会子查询的优化效果
- 2024-11-26 win10怎么查看已存储wifi密码
- 最近发表
- 标签列表
-
- cmd/c (90)
- c++中::是什么意思 (84)
- 标签用于 (71)
- 主键只能有一个吗 (77)
- c#console.writeline不显示 (95)
- pythoncase语句 (88)
- es6includes (74)
- sqlset (76)
- apt-getinstall-y (100)
- node_modules怎么生成 (87)
- chromepost (71)
- flexdirection (73)
- c++int转char (80)
- mysqlany_value (79)
- static函数和普通函数 (84)
- el-date-picker开始日期早于结束日期 (76)
- js判断是否是json字符串 (75)
- asynccallback (71)
- localstorage.removeitem (74)
- vector线程安全吗 (70)
- java (73)
- js数组插入 (83)
- mac安装java (72)
- 查看mysql是否启动 (70)
- 无效的列索引 (74)