How rh-mae/port-scanner works
Project type and purpose
• This is a standalone CLI tool (Rust Port Scanner) whose sole job is to asynchronously scan a range of TCP ports on a target IP and report which are open.
• It uses the Tokio async runtime for concurrency and Clap for command-line argument parsing.
File structure
• Top level:
• Cargo.toml / Cargo.lock – Rust package definition, dependencies (tokio, clap).
• src/main.rs – the entire application entry point and logic.
• README.md – documentation.
Extract key details from README
• Features: asynchronous scanning, timeout handling, cross-platform.
• Invocation: cargo run -- --ip <IP> --start-port <START> --end-port <END>.
• Under the hood: Clap handles CLI arguments → Tokio runtime drives asynchronous TCP connect attempts.
Main components
a. User / CLI Interface
• Entity: End user invokes the binary from a shell.
• Subcomponent: Clap parser reads --ip, --start-port, --end-port.
b. Application Core
• Component: Scanner Manager
– Initializes Tokio runtime
– Converts port range into a list of port numbers
– Schedules async tasks
• Component: Port Check Task (replicated for each port)
– Uses Tokio’s TcpStream::connect with a timeout (e.g., via tokio::time::timeout)
– Returns “open” or “closed/timeout”
c. Networking Layer
• Represents the OS’s TCP stack and network I/O
• Each Task issues a non-blocking connect request
d. Result Aggregator & Output
• Gathers successful task results
• Formats output lines to STDOUT
Relationships and data flow
• CLI Parser → Scanner Manager (init parameters)
• Scanner Manager → many Port Check Tasks (fan-out concurrency)
• Port Check Tasks → Networking Layer (async connect calls)
• Networking Layer → Port Check Tasks (ok/err result)
• Port Check Tasks → Aggregator → STDOUT
Architectural patterns and design principles
• Asynchronous concurrency (Tokio runtime, futures)
• Fan-out/fan-in pattern (spawn tasks for each port, then collect)
• Single binary, minimal layers
• Separation of concerns: argument parsing vs. scanning logic vs. output
Technologies / frameworks to annotate
• Rust (language)
• Tokio (async runtime & I/O)
• Clap (CLI argument parsing)
• std::net / tokio::net (TCP connect)
• tokio::time::timeout (timeout logic)