Created
October 28, 2018 15:55
-
-
Save josilo/67a0f89771e5e4639dcfb1ac0518b71b to your computer and use it in GitHub Desktop.
Obtain saved WiFi passwords on Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you