Measure the performance (latency) of your hosted software across all 7 layers of the OSI model, and see where you can optimize.
Two Python scripts, stdlib-only, work on Windows / macOS / Linux:
| File | Purpose |
|---|---|
network_layers_latency.py |
Prints a plain-text 7-layer latency gauge in the terminal. |
html_report.py |
Runs the same measurements and writes a self-contained HTML report with an Ask Gemini panel. |
| Layer | OSI layer | What it measures |
|---|---|---|
| L1 | Physical | Local NIC link speed (Wi-Fi / Ethernet) |
| L2 | Data Link | Local MAC address and per-interface byte counters |
| L3 | Network | ICMP ping + traceroute to the target host |
| L4 | Transport | TCP connect latency to the target host:port |
| L5 | Session | TLS handshake negotiation time |
| L6 | Presentation | Negotiated TLS cipher + protocol version |
| L7 | Application | HTTP request: DNS+TCP+TLS, TTFB, and total time |
L5 and L6 share one measurement when the URL is https://; for plain http:// there is no TLS.
- Python 3.8+ — no third-party packages, standard library only.
- A network connection to the target URL.
- Optional:
tracerouteon Linux/macOS, PowerShellGet-NetAdapteron Windows (for richer L1/L2 detail).
# Default target (Google's 204 endpoint)
python network_layers_latency.py
# Plain-text measurement of your own URL
python network_layers_latency.py --url https://my-webapp.example.com
# Self-contained HTML report
python html_report.py --url https://my-webapp.example.com --html report.htmlYou can also set the target via TARGET_URL env var.
| Flag | Long | Default | Description |
|---|---|---|---|
-u |
--url |
env / Google 204 | Target URL to measure. |
-n |
--pings |
4 |
Number of ICMP ping packets (L3). |
-H |
--hops |
5 |
Max traceroute hops (L3). |
-t |
--timeout |
5 |
Per-command / socket timeout (seconds). |
-o |
--html |
stdout | html_report.py only: write report to this path. |
--model |
gemini-3.6-flash |
html_report.py only: model pre-filled in the Ask Gemini panel. |
Every HTML report includes an Ask Gemini panel at the bottom. To use it:
- Get a free API key at Google AI Studio.
- Open the report in your browser, paste the key into the panel, edit the question if you want, and click Ask Gemini.
The key is stored only in this browser's localStorage and sent directly
from your browser to Google's API — nothing passes through any other server.
The model defaults to gemini-3.6-flash and can be changed per call.
- L4 high, L3 low → server-side TCP accept queue / SYN handling.
- L5/L6 high → certificate chain, TLS version, client CPU. TLSv1.3 should be fast.
- L7 TTFB − (L4+L5+L6) large → application server is slow before sending any body (DB query, render, upstream call, etc.).
- L1/L2 are inherently local-machine measurements. L3–L7 measure the path to the target URL.
- The scripts are dependency-free so they run anywhere Python does.