List Saved Wi-Fi Profiles on Windows Using Python

List Saved Wi-Fi Profiles on Windows Using Python (Safe Audit Script)

If you use a Windows laptop for work and personal networks, it collects a list of saved Wi-Fi profiles over time. Sometimes you just want to audit what’s stored on your machine (for cleanup, troubleshooting, or basic hygiene). This mini Python script does exactly that: it lists saved Wi-Fi profile names (SSIDs) without exposing passwords.

Why this is useful

  • Cleanup: spot old networks you don’t use anymore.
  • Troubleshooting: confirm whether a Wi-Fi profile is saved before re-adding it.
  • Security hygiene: review saved networks on shared or travel devices.

Important note

You’ll find scripts online that dump saved Wi-Fi passwords. That’s risky and easy to abuse. This version is intentionally safer: it only lists profile names. If you forgot a Wi-Fi password, the best option is to check the router label/admin page or ask the network owner/admin.

Script

import subprocess
from dataclasses import dataclass
from typing import List


@dataclass(frozen=True)
class WifiProfile:
    """Represents a saved Wi-Fi profile name (SSID/profile name)."""
    name: str


def _run_netsh(args: List[str]) -> str:
    """
    Run a netsh command safely and return stdout as text.

    - Uses a list of arguments (safer than shell=True).
    - Raises a clear error message if netsh fails.
    """
    try:
        result = subprocess.run(
            ["netsh", *args],
            capture_output=True,
            text=True,
            check=True,
        )
        return result.stdout
    except FileNotFoundError:
        raise RuntimeError("netsh not found. This script must be run on Windows.") from None
    except subprocess.CalledProcessError as e:
        msg = (e.stderr or e.stdout or "").strip()
        raise RuntimeError(f"netsh failed: {msg}") from None


def list_saved_wifi_profiles() -> List[WifiProfile]:
    """
    Return a list of saved Wi-Fi profile names on Windows.

    This does NOT extract or display passwords.
    """
    output = _run_netsh(["wlan", "show", "profiles"])

    profiles: List[WifiProfile] = []
    for line in output.splitlines():
        # netsh output typically contains lines like:
        # "    All User Profile     : MyWifiName"
        if "All User Profile" in line:
            parts = line.split(":", 1)
            if len(parts) == 2:
                name = parts[1].strip()
                if name:
                    profiles.append(WifiProfile(name=name))

    return sorted(profiles, key=lambda p: p.name.lower())


def main() -> None:
    """Print saved Wi-Fi profiles in a clean format."""
    profiles = list_saved_wifi_profiles()
    if not profiles:
        print("No saved Wi-Fi profiles found.")
        return

    print(f"Saved Wi-Fi profiles found: {len(profiles)}")
    for p in profiles:
        print(f"- {p.name}")


if __name__ == "__main__":
    main()

How to run

  1. Install Python (if needed).
  2. Save the script as list_wifi_profiles.py.
  3. Run: python list_wifi_profiles.py

Comments

Popular posts from this blog

Open SSRS Linked URLS in a new window

SSRS Font Weight expressions