Port Check: a production-ready Port Scanner in Go
Problem: Reliability vs. Speed. Many port scanners either run sequentially (too slow) or crash the system by opening thousands of unmanaged network sockets simultaneously, leading to "Too many open files" errors or being flagged by firewalls.
Action: Engineered a high-performance CLI tool using a Buffered Worker Pool architecture. Instead of unconstrained concurrency, I implemented a fixed set of workers (capped at 1,000) that pull from a job queue, providing natural backpressure and system stability.
Result: Port Check - a performant, 12-factor compliant network utility featuring:
- High-Throughput Concurrency: Scans hundreds of ports across multiple hosts in under 2 seconds without OS resource exhaustion.
- Intelligent Port Parsing: Custom engine supporting lists (22, 80, 443) and ranges (80-443) with a sort-and-deduplicate algorithm to optimize bandwidth.
- Hermetic Testing: Achieved 90%+ test coverage by mocking the network layer using ephemeral TCP servers (net.Listen).
- 12-Factor Configuration: Integrated Cobra and Viper for a robust CLI hierarchy (Flags > Env > Config File).
- Production Safety: Verified 100% thread-safe via the Go Race Detector and context-aware timeout handling.
- Modular Architecture: Decoupled scanning engine designed for easy conversion into a public Go library.