DEV Community

niuniu
niuniu

Posted on

Quick Tip — Find Every Wi-Fi Password Saved on Your Machine with Python (10 Lines, No Admin Tools)

Quick one today. I needed the Wi-Fi password for an AP I set up months ago. The Windows GUI path is: Settings → Network → Status → Properties → scroll → Security → Show characters. Five clicks, per network.

This script does it in one run:

import subprocess, re

out = subprocess.run(["netsh", "wlan", "show", "profiles"],
                     capture_output=True, text=True).stdout
profiles = re.findall(r"All User Profile\s+:\s(.+)", out)

for name in profiles:
    name = name.strip()
    detail = subprocess.run(["netsh", "wlan", "show", "profile", name, "key=clear"],
                            capture_output=True, text=True).stdout
    pw = re.search(r"Key Content\s+:\s(.+)", detail)
    print(f"{name:30} {pw.group(1) if pw else '(open network)'}")
Enter fullscreen mode Exit fullscreen mode

Example output:

HomeNet-5G                     CorrectHorseBatteryStaple
CoffeeShop-Guest               (open network)
Airport-Lounge                 flyfree2026
Enter fullscreen mode Exit fullscreen mode

Two gotchas:

  1. Run it as the same user who saved the profiles — netsh only shows what your account can see.
  2. On Linux/macOS this doesn't apply — Linux keeps them in /etc/NetworkManager/system-connections/ (needs root), macOS wants security find-generic-password -ga "SSID".

I keep this in a bin/ folder alongside other tiny scripts. Half of them were drafted with MonkeyCode, which is free for this kind of quick utility writing: https://ly.cyberserval.tech/iIETXiF

What's the smallest script you actually use weekly? Mine's probably a 3-liner that renames screenshot files by date.

Top comments (0)