Pywifi在今日頭條上看到有人在使用稍算,也嘗試的學著如果去運用,根據(jù)官網(wǎng)的鏈接嘗試的編碼是可以運行的萎胰,如果你想要更加完善闻坚,則看你的應(yīng)用領(lǐng)域在哪
參考官網(wǎng)API 文檔鏈接 (https://pypi.org/project/pywifi/)。參考github的鏈接(https://github.com/awkman/pywifi/blob/master/DOC.md)
import pywifi
from pywifi import const
profile = pywifi.Profile()
profile.ssid ='名稱' #wifi名稱
profile.auth = const.AUTH_ALG_OPEN#驗證方式
profile.akm.append(const.AKM_TYPE_WPA2PSK)#加密方式
profile.cipher = const.CIPHER_TYPE_CCMP#加密類型
profile.key ='密碼' #你要連接的wifi密碼
wifi = pywifi.PyWiFi()
iface = wifi.interfaces()[0]
temp = iface.add_network_profile(profile)
iface.connect(temp)
在這里需要注意的是逝她,需要導入 const的類浇坐,否則無法識別,這是和官網(wǎng)上有點不一樣的黔宛,接口的狀態(tài)描述你可以細究github中描述的手冊近刘,interface.status()返回的狀態(tài)信息為0~4,分別對應(yīng)const.IFACE_DISCONNECTED的各個鏈接。運行過程中還有一個坑觉渴,運行pywifi需要下載comtypes 的庫介劫。以下是未下載時的報錯信息
在參考github文中的interface.status() 則對應(yīng)上文中iface.status(),以上便是pywifi庫的使用