Skip to main content

A local-first network diagnostic tool in pure Python: architecture, a tiny i18n and a self-updater without installers

How a Windows app with a localhost server, an Edge --app window and zero dependencies stays small, translatable and self-updating.

Updated 4 min readMarkdown
A local-first network diagnostic tool in pure Python: architecture, a tiny i18n and a self-updater without installers

Airsweep is a Windows tool for checking Wi-Fi, the internet connection and the home network. One button walks computer → link → router → internet → DNS → websites and returns findings with advice. This post isn't about the network tricks (ICMP via iphlpapi, MTR-style traces, WLAN API through ctypes; I cover those in a separate post) but about the app architecture, which I wanted to keep tiny: no installer, no packages, no services.

Overview

A localhost server and an Edge window instead of a GUI toolkit

The UI is plain HTML, CSS and JavaScript with no libraries (even the QR generator for Wi-Fi passwords is written in-house). A Python http.server on 127.0.0.1 serves the page and the /api/* endpoints. The "window" is Microsoft Edge started with --app and its own profile in cache/edge, so it looks like a desktop app and doesn't touch your browsing profile. Close the window and the program exits.

Edge ships with Windows 10/11, so the user needs nothing else. Binding to 127.0.0.1 means the page is not reachable from the network. The port starts at 47811 and is written to cache/ready.txt; if it's busy, the next one is taken.

There's one gotcha with this setup: Edge offered to translate the page, because the file said <html lang="en"> while the text became Russian after the script ran. The fix is to have the server write the current language into <html lang> when serving the page, plus translate="no" and a notranslate meta tag.

i18n where the English text is the key

The UI is available in English and Russian. Instead of message IDs, the key of a translation is the English text itself, so code stays readable and a missing translation just falls back to English:

T('Network "{name}" still allows old TKIP encryption', name=ssid)

The Russian dictionary is one JSON file, lang/ru.json, shared by Python and JavaScript (the server serves it to the page as /lang.js). Placeholders are identical in both languages. A small checker, tools/i18n_check.py, lists strings that are not translated.

The interesting part is anything that gets stored. Findings, events and cached values must not be translated at creation time, otherwise they'd stay in the wrong language after a switch. So the app has P(...), which packs a message into a marker string that is translated only when it leaves the server (i18n.deep() walks every JSON response). The rule: never concatenate a packed string with + or call string methods on it, only pass it as an argument to T or P. Switching the language reloads the page, which rebuilds every table and tooltip that was created at startup.

Self-update without an installer

The app ships as a zip, so it has to update itself. updater.py does this:

  1. At start, in the background, read releases/latest from the GitHub API and compare the tag with the VERSION file.
  2. If newer, show a bar: "Version X is available, update?".
  3. On click, download airsweep-update.zip (about 200 KB, no Python inside) for that tag and verify it against the digest SHA-256 field of the API response.
  4. Replace the files. data/, cache/ and python/ are never touched.
  5. Restart without PowerShell: the app launches a new pythonw airsweep.py --restart <pid>, the old process exits, and the new one waits until the port is free.

The release notes have ## What's new and ## Что нового sections, and their list items become the text in the update bar in the right language. I tested the whole flow on a copy by overriding the API and zip addresses through environment variables (file:// URLs work too) and against the real release for the check and download. The full "real new version, click the button" cycle will only be visible when 1.1 comes out.

Wi-Fi nearby

Measurements

On my PC (Windows 10, wired), python.exe only, the Edge window counted separately:

  • start to a ready server: about 0.4 s
  • idle: 36 MB, 8 threads, no measurable CPU use
  • peak during a full check: 44 MB, up to 29 threads
  • the full check takes about 30 s
  • release zip 11.4 MB with bundled Python 3.11, update zip 0.2 MB, about 4.9k lines of Python and 490 KB of web files

Limits

The "connected over Wi-Fi" branch was checked against sample netsh output, because my PC uses a cable. A strict antivirus may dislike a program that reads Wi-Fi profiles and scans the network (the code is open and plain Python). Admin rights are needed for reading a saved Wi-Fi password and for repair actions, so Windows will show a UAC prompt there.

Get it

Windows 10/11 (64-bit) with Edge. Unpack, run Airsweep.bat.

Download: https://github.com/OlegChe77/airsweep/releases/latest/download/airsweep.zip Source (MIT): https://github.com/OlegChe77/airsweep

No comments yet. Be the first to comment.