python self-study-class26(down)-wifi scan link

1. wifi scanning

import pytest
import sys
import time
import platform
import logging
import pywifi
from pywifi import const
pywifi.set_loglevel(logging.INFO)
def wifi_scan():
    wifi=pywifi.PyWiFi()  #初始化wifi
    iface=wifi.interfaces()[0] #第一个无线网卡
    iface.scan()  #扫描
    time.sleep(5)
    bsses=iface.scan_results()  #扫描结果
    for data in bsses:   #每一个wifi创建一个对象
        print(data)
    #assert bsses
wifi_scan()

2. Test the wireless network card

import pytest
import sys
import time
import platform
import logging
import pywifi
from pywifi import const
pywifi.set_loglevel(logging.INFO)
def wifi_interfaces():
    wifi=pywifi.PyWiFi()  #初始化wifi
    assert wifi.interfaces()  #抓取网卡接口
    if platform.system().lower()=='windows':  #判断平台
        assert wifi.interfaces()[0].name()==\
            'Realtek 8822BE Wireless LAN 802.11ac PCI-E NIC'

wifi_interfaces()

3. Test link

# vim: set fileencoding=utf-8
import pytest
import sys
import time
import platform
import logging

# For mocking
import os
import stat
import socket

import pywifi
from pywifi import const
pywifi.set_loglevel(logging.INFO)
def test_connect():
    try:
        wifi = pywifi.PyWiFi()  #wifi对象

        iface = wifi.interfaces()[0]  #第一个网卡

        iface.disconnect()  #断开所有无线连接
        time.sleep(1)
        profile = pywifi.Profile() #连接wifi初始化构造
        profile.ssid = '上我呀' #wifi名称
        profile.auth = const.AUTH_ALG_OPEN  #开放的
        profile.akm.append(const.AKM_TYPE_WPA2PSK)  #默认加密算法
        profile.cipher = const.CIPHER_TYPE_CCMP#wifi数据类型
        profile.key = '12345678'  #wifi密码

        iface.remove_all_network_profiles()  #卸载当前所有网络WiFi
        tmp_profile = iface.add_network_profile(profile) #增加一个profile,链接wifi

        iface.connect(tmp_profile)  #根据profile链接wifi
        time.sleep(5)#休眠5s
        isOK=False
        if iface.status() == const.IFACE_CONNECTED:#连接上的状态
            isOK=True
            print("链接成功")

        iface.disconnect()
        if isOK:
            return
        time.sleep(1)
        if iface.status() in\
               [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]:#链接失败,断开所有wifi
            print("链接失败")
    except AssertionError:
        pass


test_connect()

Summary: The function here, if there is a codebook that includes all the passwords, you can continuously test the link wifi to achieve the role of brute force cracking of the password.

Guess you like

Origin blog.csdn.net/weixin_46837674/article/details/114238473