Skip to content

levyvix/port_scan

Repository files navigation

Port Scan

A high-performance network port scanner written in Python that scans multiple IP addresses and port ranges concurrently using multiprocessing.

Features

  • Parallel Scanning: Uses multiprocessing for fast concurrent port scanning
  • Network Support: Supports individual IPs and CIDR notation for network ranges
  • Port Ranges: Accepts single ports or port ranges (e.g., 80-443)
  • Network Grouping: Automatically groups results by /24 networks
  • Dual Reports: Generates both detailed and summary reports
  • Type Safety: Full type hints for better code maintainability

Installation

Prerequisites

  • Python 3.10 or higher
  • uv package manager (recommended) or pip

Install Dependencies

Using uv (recommended):

uv sync

Using pip:

pip install -r requirements.txt

Usage

  1. Prepare your target file (ips_formatados.txt) with IP addresses and ports:

    192.168.1.1 80
    192.168.1.1 443
    10.0.0.0/24 22-25
    192.168.2.100 3306
    
  2. Run the scanner:

    python port_scan.py

    Or with uv:

    uv run python port_scan.py

Input Format

The input file should contain lines with IP addresses/networks and ports, separated by spaces:

  • Individual IPs: 192.168.1.1 80
  • Network ranges: 10.0.0.0/24 22 (scans all hosts in the network)
  • Port ranges: 192.168.1.1 80-443 (scans ports 80 through 443)
  • Comments: Lines starting with # are ignored
  • Empty lines: Ignored

Output

The scanner generates two report files:

relatorio_redes.txt (Detailed Report)

Shows all IPs with open ports, grouped by /24 network:

=== Rede 192.168.1.0/24 ===
Porta 80 aberta em 3 IPs:
  - 192.168.1.10
  - 192.168.1.15
  - 192.168.1.20
Porta 443 aberta em 2 IPs:
  - 192.168.1.10
  - 192.168.1.15

relatorio_resumido.txt (Summary Report)

Shows counts of accessible IPs per port per network:

Resumo por rede:

Rede 192.168.1.0/24:
  - Porta 80: 3 IPs acessíveis
  - Porta 443: 2 IPs acessíveis

Configuration

  • Workers: Default 20 concurrent processes (configurable in scan_targets())
  • Timeout: Default 3 seconds per port connection attempt
  • Input file: ips_formatados.txt (hardcoded in main)

Dependencies

  • loguru: Structured logging
  • ipaddress: IP network manipulation (stdlib)
  • socket: Network connections (stdlib)
  • multiprocessing: Parallel processing (stdlib)

Development

Type Checking

mypy .

Code Quality

Consider adding:

  • ruff for linting
  • black for code formatting
  • pytest for testing

License

This project is open source. Please check the license file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages