AyanUpadhaya

Extract Connected WIFI passwords with python | For windows

Nov 26th, 2021 (edited)
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. import subprocess
  2. import re
  3.  
  4. # subprocess for running system commands
  5. command_output=subprocess.run(["netsh","wlan","show","profiles"],capture_output=True).stdout.decode()
  6.  
  7. profile_names= (re.findall("All User Profile     : (.*)\r",command_output))
  8.  
  9. #username and passwords will be saved in a list
  10. wifi_list = list()
  11.  
  12. if len(profile_names)!=0:
  13.     # every wifi profile will have its own dictionary
  14.     for name in profile_names:
  15.         wifi_profile = dict()
  16.         # if security key is not absent then we can get passwords for sure
  17.  
  18.         profile_info = subprocess.run(["netsh","wlan","show","profiles",name],capture_output=True).stdout.decode()
  19.  
  20.         if re.search("Security key      :Absent",profile_info):
  21.             continue
  22.         else:
  23.             wifi_profile["ssid"]= name
  24.             profile_info_pass = subprocess.run(["netsh","wlan","show","profile",name,"key=clear"],capture_output=True).stdout.decode()
  25.             password = re.search("Key Content            : (.*)\r",profile_info_pass)
  26.  
  27.             if password == None:
  28.                 wifi_profile["password"]=None
  29.             else:
  30.                 wifi_profile["password"]=password[1]
  31.  
  32.                 # then we append wifi information to wifi_list
  33.             wifi_list.append(wifi_profile)
  34.  
  35. for x in range(len(wifi_list)):
  36.     print(wifi_list[x])
Add Comment
Please, Sign In to add comment