Skip to content

Instantly share code, notes, and snippets.

@josilo
Created October 28, 2018 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josilo/67a0f89771e5e4639dcfb1ac0518b71b to your computer and use it in GitHub Desktop.
Save josilo/67a0f89771e5e4639dcfb1ac0518b71b to your computer and use it in GitHub Desktop.
Obtain saved WiFi passwords on Windows
import subprocess
import locale
import sys
enc = locale.getpreferredencoding()
def call(cmd):
r, e = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()
return r.decode(enc)
net = []
for p in call('netsh wlan show profile').splitlines():
if " : " in p:
ssid = p.split(":")[1].strip()
data = []
block_index = 0
for d in call('netsh wlan show profile name="{}" key=clear'.format(ssid)).splitlines():
d = d.strip()
if '-' in d and len(set(d)) == 1:
block_index = block_index + 1
if block_index == 3 and len(d.strip()) != 0 and ":" in d:
data.append(d)
# Checks if has a key:
if data[-1].split(":")[1].strip() != "1":
net.append({"ssid": ssid, "password": data[-1].split(":")[1].strip()})
if "--json" in sys.argv:
print({"networks": net})
else:
for n in net:
print("{} : {}".format(n["ssid"], n["password"]))
@CryptoV7
Copy link

Nıce Command

@sakura237
Copy link

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment