Skip to content

Add async scanning with asyncio for faster port scans #1

@stabrea

Description

@stabrea

Summary

Replace the current threading-based port scanning with Python asyncio for significantly faster and more scalable network scanning.

Motivation

  • Threading in Python is limited by the GIL and has high overhead per-thread
  • asyncio with non-blocking sockets can handle thousands of concurrent connections
  • Modern Python (3.11+) has significant asyncio performance improvements
  • Scan times for large port ranges (1-65535) can drop from minutes to seconds

Proposed Approach

  1. Async scanner module:

    • Use asyncio.open_connection() for TCP connect scans
    • Semaphore-based concurrency limiting (configurable, default 1000)
    • Timeout handling per-connection with asyncio.wait_for()
  2. SYN scan support:

    • Raw socket async SYN scanning (requires root/sudo)
    • Fallback to connect scan when privileges unavailable
  3. Progress reporting:

    • Async progress callback for real-time scan updates
    • ETA calculation based on scan rate
  4. Backward compatibility:

    • Keep existing synchronous API as wrapper
    • Add --async flag to CLI for opt-in

Benchmarks to Target

Scan Type Current (threading) Target (asyncio)
Top 1000 ports ~30s <5s
Full 65535 ports ~10min <45s

Acceptance Criteria

  • Async scanner with configurable concurrency
  • At least 5x speedup on full port range scans
  • Progress reporting during long scans
  • Existing CLI interface preserved with async option

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions