Last active
August 29, 2015 14:13
-
-
Save techtonik/ddf36e5f63dc48eb08e7 to your computer and use it in GitHub Desktop.
Windows WiFi: List sorted Profile data (requires admin)
This file contains 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
# Windows stores configured WiFi networks as Profile | |
# [ ] this needs to be run under administrator | |
# [ ] detect that it is not | |
try: | |
import _winreg # Python 2 | |
except ImportError: | |
import winreg # Python 3 | |
profiles = r'HKLM\Software\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles' | |
def openKey(fullkey): | |
root, sub = fullkey.split('\\', 1) | |
if root == 'HKLM': | |
root = _winreg.HKEY_LOCAL_MACHINE | |
else: | |
raise NotImplemented(key) | |
return _winreg.OpenKeyEx(root, sub, 0, _winreg.KEY_READ) | |
def subkeyNames(fullkey): | |
key = openKey(fullkey) | |
numkeys, _, lastmod = _winreg.QueryInfoKey(key) | |
res = [] | |
for i in range(numkeys): | |
res.append(_winreg.EnumKey(key, i)) | |
_winreg.CloseKey(key) | |
return res | |
def getValue(fullkey, name): | |
key = openKey(fullkey) | |
res, regtype = _winreg.QueryValueEx(key, name) | |
_winreg.CloseKey(key) | |
return res | |
nets = [] | |
for subkey in subkeyNames(profiles): | |
entry = subkey, getValue(profiles + r'\%s' % subkey, 'ProfileName'), getValue(profiles + r'\%s' % subkey, 'NameType') | |
nets.append(entry) | |
#print("%s %s" % (subkey, getValue(profiles + r'\%s' % subkey, 'ProfileName'))) | |
#print("%s %s" % (subkey, hexdump.dump(getValue(profiles + r'\%s' % subkey, 'DateCreated')))) | |
nets.sort(key=lambda x: x[1]) | |
for n in nets: | |
print(n[0], n[2], n[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment