import
os
import
sys
import
xlwt
import
time
from
datetime
import
datetime
def
checkWIFI():
list
=
[]
message
=
os.popen(
'netsh wlan show profiles'
).readlines()
if
(message[
0
].find(u
"没有运行"
)) !
=
-
1
:
return
message[
0
]
for
i
in
message:
result
=
i.strip().encode(
'gb2312'
).decode(
'gb2312'
,
'strict'
)
if
result.find(u
"所有用户配置文件 : "
) !
=
-
1
:
command
=
'netsh wlan show profiles name="'
+
result[
11
:]
+
'" key=clear'
per_wifi
=
os.popen(command.encode(
'gb2312'
).decode(
'gb2312'
)).readlines()
for
j
in
per_wifi:
passwd
=
j.strip().encode(
'gb2312'
).decode(
'gb2312'
,
'strict'
)
if
passwd.find(u
"关键内容 :"
) !
=
-
1
:
if
passwd[
18
:] !
=
'':
list_temp
=
[]
list_temp.append(result[
11
:])
list_temp.append(passwd[
18
:])
list
.append(list_temp)
return
list
def
write_data_to_excel(result,name):
wbk
=
xlwt.Workbook(encoding
=
'utf-8'
)
sheet
=
wbk.add_sheet(
'Sheet1'
,cell_overwrite_ok
=
True
)
today
=
datetime.today()
today_date
=
datetime.date(today)
for
i
in
range
(
len
(result)):
for
j
in
range
(
len
(result[i])):
sheet.write(i,j,result[i][j])
excel_name
=
name
+
"_"
+
str
(today_date)
+
'.xls'
wbk.save(excel_name)
if
__name__
=
=
'__main__'
:
print
(
"正在查询......"
)
password_list
=
checkWIFI()
print
(
"\n返回结果如下:\n"
)
if
isinstance
(password_list,
list
):
for
n
in
password_list:
print
(
"[+]"
+
"\t Wifi:\t"
+
n[
0
]
+
"\n\tPassword:\t"
+
n[
1
]
+
"\n"
)
write_data_to_excel(password_list,
"WifiPassword"
)
elif
isinstance
(password_list,
str
):
print
(
"[-]\t"
+
password_list)
print
(
"10秒后退出"
)
time.sleep(
10
)