How matinsenpai/senpaiscanner works
1. What this repository is
- senpaiscanner is a Go command-line application with a full terminal UI for finding Cloudflare IPs that are reachable and fast from the user’s network.
- It is not a library-first project: the executable entrypoint is cmd/senpaiscanner, and most behavior lives in internal/*.
2. Top-level runtime shape
- The app is a single interactive TUI process: the user opens the menu, chooses a scan mode, and the UI drives the rest of the workflow.
- There are no scan-oriented CLI subcommands or flags in normal use; the only common non-TUI path is version reporting.
3. UI / interaction boundary
- internal/ui contains the terminal screens and navigation state:
- model.go holds UI state,
- pages.go defines the menu and screen transitions,
- cmds.go likely defines asynchronous actions/messages for scans and navigation.
- This layer is the boundary between human input and the scanning engine. It starts scans, shows live tables, handles cancel/back, and later shows the results screen.
4. Configuration boundary
- internal/config is the schema for scan settings coming from the TUI forms.
- It captures the scan mode and operational parameters such as count, workers, timeout, tries, port, CIDR filter, SNI, IPv4/IPv6 toggles, colo filter, and output path.
- Quick Scan, Custom Scan, Test IPs, and Discover Colos are all different presets feeding the same lower-level scan machinery.
5. Scan orchestration
- internal/engine is the coordinator between configuration, IP source, probing, result aggregation, and output.
- It owns the lifecycle of a scan: start, fan out work to workers, collect probe results, handle cancellation, and decide when the UI should move to Results.
- This is the main “business logic” boundary of the repo.
6. IP source generation
- internal/ipsrc supplies candidate Cloudflare addresses.
- The repository embeds Cloudflare IPv4/IPv6 range snapshots in ranges_v4.txt and ranges_v6.txt, rather than fetching them at runtime.
- That means address selection is deterministic per build and independent of network access until probing begins.
7. Probing / validation layer
- internal/prober performs the actual network checks against candidate IPs.
- The README shows three materially different validation modes:
- TCP: socket reachability,
- TLS: handshake validation,
- HTTP/HTTPS: real request validation through Cloudflare endpoints.
- External endpoints matter here: speed.cloudflare.com is used for trace/download behavior, and /cdn-cgi/trace plus CF-Ray are used to identify the colo.
8. Result model and ranking
- internal/result is the shared data model for probe outcomes.
- It holds the metrics the scanner ranks by: latency, loss, jitter, download throughput, colo, TLS/HTTP status, and whether a speed test was performed.
- The UI’s “Results” page and live scan table are both driven from this result abstraction.
9. Output pipeline
- internal/output is the file-export boundary.
- When the user provides an output path in Custom Scan, results are streamed to disk in one of three formats: CSV, JSON, or TXT.
- Important architectural point: output is incremental during the scan, not only after completion.
10. User-visible scan modes map to one backend
- Quick Scan and Custom Scan are the same engine with different presets and UI entry points.
- Test IPs reads ips.txt from the working directory and validates a user-provided list rather than random Cloudflare ranges.
- Discover Colos is a specialized HTTP-only sweep that groups healthy results by colo and reports average/best latency.
- This shows the repo is centered on a shared probing pipeline with multiple front-end workflows.
11. External services and network assumptions
- The app depends on Cloudflare’s public infrastructure, especially their published IP ranges and trace/speed endpoints.
- It is designed for unstable or restricted networks, so concurrency, timeout, retry count, and protocol choice materially affect behavior.
- The colo filter and SNI handling exist because the network path and TLS identity are important to real-world success, not just raw reachability.
12. Build, release, and packaging
- The project uses standard Go tooling plus Makefile, GitHub Actions (ci.yml, release.yml), and GoReleaser (.goreleaser.yaml) to produce platform binaries.
- install.sh provides a shell-based install path from GitHub releases.
- pkg/version centralizes version stamping for the binary and --version output.
13. Architecture summary for a diagram
- A clean diagram would show: terminal user → UI/state machine → config → engine → ipsrc + prober → result aggregation → UI/results and optional output file.
- Cloudflare endpoints sit outside the app as the external network dependency, while embedded IP range files are an internal static data source.
Main entry points: engine.go Engine · ipsrc.go IP source · prober.go Prober · main.go Main
Components 18
Runtime
Interactive application flow
- User · Terminal operator driving scans
- Main · Program startup and version dispatch
cmd/senpaiscanner/main.go - UI state · Screen state and navigation model
internal/ui/model.go - Pages · Menu and screen transitions
internal/ui/pages.go - UI cmds · Async commands and messages
internal/ui/cmds.go - Banner · Startup banner and branding text
internal/banner/banner.go - Terminal UI · Interactive screen presented to the user
Core
Scanning and data pipeline
- Config · Scan modes and operational parameters
internal/config/config.go - Engine · Coordinates scanning lifecycle and cancellation
internal/engine/engine.go - IP source · Produces Cloudflare IP candidates
internal/ipsrc/ipsrc.go - Prober · TCP, TLS, and HTTP validation
internal/prober/prober.go - Output · Streams scan results to files
internal/output/output.go
Data
Static inputs and shared models
- Results · Shared probe outcomes and ranking metrics
internal/result/result.go - IPv4 ranges · Bundled Cloudflare IPv4 snapshot
internal/ipsrc/ranges_v4.txt - IPv6 ranges · Bundled Cloudflare IPv6 snapshot
internal/ipsrc/ranges_v6.txt
Other components
- Cloudflare · Published ranges and trace/speed endpoints
- Results file · CSV, JSON, or TXT scan output
Connections 20
- User → Terminal UI: uses · Operates the interactive scanner
- Terminal UI → Pages: navigates · Moves through menu and scan screens
- Pages → UI state: updates · Maintains current screen and scan state
- Pages → UI cmds: triggers · Starts scans and async actions
- UI cmds → Config: builds · Collects scan settings from forms
- Config → Engine: feeds · Passes scan mode and parameters
- Engine → IP source: requests · Gets candidate IP addresses
- IP source → IPv4 ranges: reads · Uses bundled IPv4 ranges
- IP source → IPv6 ranges: reads · Uses bundled IPv6 ranges
- IP source → Prober: yields · Supplies candidate addresses for validation
- Engine → Prober: orchestrates · Fans out probes and handles cancellation
- Prober → Cloudflare: targets · Checks reachability and Cloudflare behavior
- Prober → Results: emits · Produces probe outcomes and metrics
- Engine → Results: aggregates · Ranks and collects results
- Results → UI state: renders · Drives live table and results screen
- Engine → Output: streams · Writes incremental scan output
- Output → Results file: writes · Exports CSV, JSON, or TXT
- Main → Version: reports · Supports version output
- Main → Banner: shows · Displays startup branding
- Main → UI state: starts · Launches the interactive application