Skip to content

Commit 79176f4

Browse files
authored
Merge pull request #238 from Ninjavin/wifi-password-ninjavin
Write all saved wifi passwords in separate text file in Python
2 parents 4ddc5b7 + 7f659d5 commit 79176f4

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Write all saved passwords in a file
2+
3+
Run `python3 wifi-password.py` and a text file with all saved passwords will be stored in the project folder.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os
2+
import subprocess
3+
# For Linux OS
4+
if os.name=='posix':
5+
output = subprocess.run(["nmcli", "-g", "NAME", "connection", "show"], capture_output=True)
6+
allWifi = output.stdout.decode('utf-8', errors='strict')
7+
allWifiList = allWifi.split("\n")
8+
allWifiList.pop()
9+
wifiPasslist = []
10+
for wifi in allWifiList:
11+
password = subprocess.run(["nmcli", "-s", "-g", "802-11-wireless-security.psk", "connection", "show", wifi], capture_output=True)
12+
wifiPasslist.append(wifi + ": " + password.stdout.decode('utf-8', errors="strict"))
13+
f = open('wifi-passwords-linux.txt', 'w')
14+
f.writelines(wifiPasslist)
15+
# For Windows OS
16+
if os.name=='nt':
17+
output = subprocess.run(["netsh", "wlan", "show", "profiles"], capture_output=True)
18+
allWifi = output.stdout.decode('utf-8', errors='strict')
19+
allWifiList = allWifi.split('\n')
20+
completePasswordList = []
21+
wifiProfileList = []
22+
for wifi in allWifiList:
23+
if "All User Profile" in wifi:
24+
temp = wifi.split(":")
25+
wifiName = temp[1]
26+
# Final Profile Name
27+
wifiName = wifiName[1:-1]
28+
wifiProfileList.append(wifiName)
29+
for profile in wifiProfileList:
30+
output2 = subprocess.run(["netsh", "wlan", "show", "profile", profile, "key=clear"], capture_output=True)
31+
allWifi2 = output2.stdout.decode('utf-8', errors='strict')
32+
allWifiList2 = allWifi2.split('\n')
33+
for wifi in allWifiList2:
34+
if "Key Content" in wifi:
35+
temp2 = wifi.split(":")
36+
wifiPass = temp2[1]
37+
# Final Password
38+
wifiPass = wifiPass[1:-1]
39+
print("Password : " + wifiPass)
40+
completePasswordList.append(profile + ": " + wifiPass + "\n")
41+
f = open('wifi-passwords-win.txt', 'w')
42+
f.writelines(completePasswordList)

0 commit comments

Comments
 (0)