How bia-pain-bache/cloudflare-clean-ip-scanner works
1. This repository is a single Go command-line binary, not a service. Its job is to benchmark Cloudflare CDN IPs and pick the fastest candidate based on latency, loss, and optional download throughput.
2. main.go is the orchestration layer. It parses flags, loads the IP inventory, chooses the probe mode, runs the test pipeline, sorts/filter results, and controls whether results are printed or written to disk.
3. The input boundary is file- and flag-driven. The default IP datasets are ip.txt for IPv4 and ipv6.txt for IPv6, but users can also supply custom ranges via -f or inline ranges via -ip. The tool supports both single IPs and CIDR ranges, and can either sample one IP per range or test every IPv4 address with -allip.
4. The probing subsystem lives under task/ and is split by responsibility:
- task/tcping.go for default TCP-based latency tests
- task/httping.go for HTTP-based latency tests and region matching
- task/download.go for sequential download speed testing
- task/ip.go for IP-range parsing, expansion, and candidate selection
5. The pipeline is staged. First it performs a concurrency-heavy latency sweep across the candidate IPs. Then it filters by configured latency and packet-loss bounds. Only the remaining “queue” proceeds to the slower, one-by-one download benchmark, which is why the final result set can be much smaller than the initial probe count.
6. There are two distinct latency modes with different semantics. TCPing is the default and lighter-weight. HTTPing is used when the user wants protocol-level reachability checks against a specific URL, and it also enables Cloudflare/AWS CloudFront colo filtering by airport code. That means the architecture has both transport-level and application-level probe paths.
7. The output subsystem is split between terminal progress and CSV persistence. utils/progress.go handles live progress-bar/status reporting, while utils/csv.go serializes the final ranking to result.csv or a user-specified path. The result schema is fixed around sent/received counts, loss rate, average latency, and download speed.
8. Sorting and ranking happen after each stage. Latency is used as the first gate, then download speed becomes the primary ranking signal when the download phase is enabled. If download testing is disabled with -dd, the final ordering is latency-based instead.
9. The repo is designed for offline execution with external network dependencies only at probe time. It talks to Cloudflare endpoints or user-specified URLs to measure connectivity and throughput, but it does not depend on a backend API or database.
10. Platform-wise, the application targets Windows and Linux as a portable Go binary. The GitHub Actions workflow under .github/workflows/build.yml is for CI packaging/release builds, while go.mod/go.sum define the Go runtime and dependencies.
11. For an architecture diagram, the most important boundaries are:
- configuration/input layer: CLI flags + IP files
- probe engine: TCPing/HTTPing/download workers
- filtering/sorting layer: latency, loss, speed thresholds
- presentation/output layer: console progress + CSV export
12. The core data flow is:
IP inventory in → candidate selection/expansion → concurrent latency probes → threshold filtering → optional serialized download probes → ranking → terminal output and/or CSV file.
Main entry points: main.go main.go · httping.go HTTPing · ip.go IP parser · tcping.go TCPing
Components 17
Input & config
CLI flags and IP inventory sources
Probe engine
Latency, reachability, and throughput workers
- IP parser · Loads single IPs and CIDR ranges, expands or samples candidates
task/ip.go - TCPing · Default TCP-based latency and loss test
task/tcping.go - HTTPing · Protocol-level reachability test with region matching
task/httping.go - Download test · Sequential download benchmark for surviving candidates
task/download.go
Ranking pipeline
Filtering, sorting, and final selection
- Latency sweep · High-concurrency probing across the candidate IP set
- Threshold filter · Filters by latency and packet-loss bounds
- Download queue · Smaller set of best candidates that proceed to throughput testing
- Ranking · Orders by download speed when enabled, otherwise by latency
Output
Progress reporting and CSV persistence
- Progress UI · Live progress-bar and status output during probing
utils/progress.go - CSV export · Writes final ranking to result.csv or a user-specified path
utils/csv.go
Other components
- Cloudflare endpoints · External measurement target used for probing
- User URL · Optional user-specified HTTP endpoint for application-level checks
- Build workflow · GitHub Actions build and release packaging
.github/workflows/build.yml - Go module · Defines the Go runtime and dependencies
go.mod
Connections 19
- main.go → IP lists: reads · Uses the default IPv4 inventory
- main.go → IPv6 list: reads · Uses the default IPv6 inventory
- main.go → IP parser: loads · Parses files, inline ranges, or custom IP input
- IP parser → Latency sweep: candidates · Produces sampled or expanded probe candidates
- main.go → TCPing: default mode · Runs TCPing when HTTPing is not selected
- main.go → HTTPing: optional mode · Runs HTTP-level probes when requested
- TCPing → Cloudflare endpoints: measures · Probes Cloudflare IPs for latency and loss
- HTTPing → Cloudflare endpoints: measures · Uses HTTP reachability against Cloudflare targets
- HTTPing → User URL: optional · Can probe a user-specified URL
- Latency sweep → Threshold filter: results · Outputs latency and packet-loss measurements
- Threshold filter → Download queue: passes · Only surviving candidates enter download testing
- Download queue → Download test: tests · Runs sequential throughput benchmarks
- Download test → Ranking: scores · Produces download-speed results for final ordering
- Threshold filter → Ranking: sorts · Latency-based ordering when download testing is disabled
- main.go → Progress UI: reports · Streams live progress and status updates
- Ranking → CSV export: writes · Persists the final ranked results
- Ranking → main.go: returns · Feeds final results back to orchestration for printing
- main.go → Build workflow: builds · CI workflow packages binaries for release
- main.go → Go module: depends on · Uses the module definition and dependency graph