$ show XIU2/CloudflareSpeedTest
CloudflareSpeedTest is a CLI tool written in Go that measures latency and download speed of Cloudflare CDN IP addresses to find the fastest ones for users in China, where many Cloudflare IPs are suboptimal. It reads IP ranges from files (ip.txt/ipv6.txt) or command-line arguments, performs concurrent TCP or HTTP ping tests, filters results by latency/loss rate, then conducts HTTP download speed tests on the lowest-latency IPs. The final output is a sorted list of the best IPs displayed in the console and saved to a CSV file. The tool supports extensive customization: thread count, ping count, port, download test duration, speed/latency thresholds, colocation filtering via HTTP headers, and debug logging. It also includes helper scripts for automatically updating system hosts files, 3proxy configurations, or Cloudflare DNS records with the optimal IP. The architecture is a single binary with modular task files (tcping, httping, download, ip parsing) and utility modules (color output, CSV export, progress bar). External dependencies are minimal: ewma for moving average, pb for progress bars, and color for terminal colors. The codebase is well-structured with clear separation of concerns, though it lacks automated tests and CI pipelines. It is a practical, community-driven tool with over 29k stars, actively maintained with recent commits and responsive issue triage.
The LLM identified 2 files worth highlighting for reuse:
Implements a reusable sorting interface for custom data types (PingDelaySet, DownloadSpeedSet) by defining Len, Less, and Swap methods. This pattern allows the standard sort.Sort function to operate on these types polymorphically, decoupling sorting logic from data structure. The same approach can be extracted and applied to any collection that needs custom comparison logic, demonstrating a clean separation of concerns.
Contains the getHeaderColo function that extracts geographic location codes (IATA airport codes, country codes, city codes) from HTTP response headers of multiple CDNs (Cloudflare, AWS CloudFront, Fastly, Gcore, CDN77, Bunny). This is a self-contained utility that can be reused in any project needing to determine which CDN edge server handled a request, without requiring the rest of the speed-testing infrastructure. It demonstrates careful handling of different header formats and fallback logic.