netsh wlan show profiles
netsh wlan show profile name=wifi名称 key=clear
应用于win系统
本人win10,并没有在其他电脑测试过
# !/usr/bin/env/python
# _*_coding:utf-8_*_
# Data:2019-07-03
# Auther:苏莫
# Link:QQ2388873062
# PythonVersion:python2.7
# filename:get_win_wifi_pwd.py
__author__ = u'苏莫'
__date__ = '$2019-07-03$'
import os
import sys
import msvcrt
reload(sys)
sys.setdefaultencoding('utf-8')
"""
读取win系统已连接过的wifi密码
"""
# 获取连接过的wifi名称
cat_wifi = "netsh wlan show profiles"
# 该wifi的相应密码
cat_pwd = "netsh wlan show profile name=[] key=clear"
# 获取wifi列表
def get_wifi_lis():
global cat_wifi
wifi_lists = []
all_msg = os.popen(cat_wifi)
for tmp in all_msg.readlines():
if ":" in tmp:
mid_tmp = tmp.split(":")
if mid_tmp[1].strip() != '':
wifi_lists.append(mid_tmp[1].strip())
# print mid_tmp
return wifi_lists
# wifi及对应密码
def get_wifi_pwd(wifi_lists):
global cat_pwd
wifi_pwd = {}
for line_wifi in wifi_lists:
shell = cat_pwd.replace("[]", line_wifi)
all_msg = os.popen(shell)
pwd = ''
for tmp in all_msg.readlines():
if "\xb9\xd8\xbc\xfc\xc4\xda\xc8\xdd" in tmp:
pwd = tmp.split(":")[1].strip()
# print pwd
wifi_pwd[line_wifi] = pwd
return wifi_pwd
# 打印输出
def print_msg(wifi_msg):
print "name\t\tkey"
print "-"*40
for i,j in wifi_msg.items():
print i,
print "\t",
print j
print "-"*40
# 保存文件
def write_msg(wifi_msg):
with open("wifi_pwd.txt",'w') as f:
f.write('name\t\tkey'+os.linesep)
f.write("-"*40+os.linesep)
for i,j in wifi_msg.items():
f.write(i+"\t"+j+os.linesep)
print u"保存完成!!!"
# 主函数
def main():
been_wifi = get_wifi_lis()
wifi_msg = get_wifi_pwd(been_wifi)
print_msg(wifi_msg)
write_msg(wifi_msg)
print "-"*40
print u'输入任意键退出...'
msvcrt.getch()
if __name__ == '__main__':
main()
如果您愿意花几块钱请我喝杯茶的话,可以用手机扫描下方的二维码,通过支付宝或者微信直接向我捐赠呦。