|
| 1 | +import glob |
| 2 | +import os |
| 3 | +import subprocess |
| 4 | +import xml.etree.ElementTree as ET |
| 5 | + |
| 6 | +class PwdDisplay: |
| 7 | + def __init__(self): |
| 8 | + # Définition du répertoire courant |
| 9 | + os.chdir("./") |
| 10 | + # Création du dossier mot de passe |
| 11 | + if not os.path.exists("passwords"): |
| 12 | + os.system("mkdir passwords") |
| 13 | + |
| 14 | + self.export_xml(command="netsh wlan export profile interface=wi-fi key=clear folder=passwords") |
| 15 | + self.display_password() |
| 16 | + |
| 17 | + def export_xml(self, command=None): |
| 18 | + with open("tmp.txt", "w") as tmp: |
| 19 | + export_command = command.split(' ') |
| 20 | + subprocess.run(export_command,stdout=tmp) |
| 21 | + os.remove("tmp.txt") |
| 22 | + |
| 23 | + def file_path(self) -> list[str]: |
| 24 | + # Obtention du chemin des fichiers xml |
| 25 | + chemin_fichiers = glob.glob("passwords/"+"*xml") |
| 26 | + return chemin_fichiers |
| 27 | + |
| 28 | + def get_ssid_pwd(self) -> list: |
| 29 | + ssid_pwd = {} |
| 30 | + for i in self.file_path(): |
| 31 | + tree = ET.parse(i) |
| 32 | + root = tree.getroot() |
| 33 | + ssid = root[1][0][1].text # ssid |
| 34 | + pwd = root[4][0][1][2].text #pwd |
| 35 | + ssid_pwd[ssid] = pwd |
| 36 | + return ssid_pwd |
| 37 | + |
| 38 | + def display_password(self): |
| 39 | + index=1 |
| 40 | + info = self.get_ssid_pwd() |
| 41 | + list_ssid, list_pwd = [], [] |
| 42 | + print("Here is the list of Wi-Fi networks registered on this device : \n") |
| 43 | + for i in info: |
| 44 | + print(f"[{index}] {i}") |
| 45 | + list_ssid.append(i) |
| 46 | + list_pwd.append(info[i]) |
| 47 | + index+=1 |
| 48 | + |
| 49 | + nb = int(input("Please choose a number : ")) |
| 50 | + print(f"SSID : {list_ssid[nb-1]}\nPassword : {list_pwd[nb-1]}\n") |
| 51 | + |
| 52 | + def __del__(self): |
| 53 | + print("Thanks for using my tool :)") |
| 54 | + # Supression des fichiers |
| 55 | + for i in self.file_path(): |
| 56 | + if os.path.exists(i): |
| 57 | + os.remove(i) |
| 58 | + |
| 59 | + |
| 60 | +if __name__ == '__main__': |
| 61 | + instance = PwdDisplay |
| 62 | + instance() |
0 commit comments