Skip to content

Simple Port Scanner

CarterPerez-dev edited this page Feb 11, 2026 · 1 revision

Simple Port Scanner

Concurrent TCP port scanner written in C++ with async I/O and banner grabbing.

Overview

A high-performance TCP port scanner using Boost.Asio for asynchronous I/O. Probes target hosts to identify open, closed, and filtered ports with concurrent scanning of hundreds of ports simultaneously. Includes service banner grabbing for fingerprinting.

Status: Complete | Difficulty: Beginner

Legal Disclaimer

This tool is for authorized security testing only. Only scan systems you own or have explicit written permission to test. Unauthorized port scanning may be illegal.

Tech Stack

Technology Version Purpose
C++ C++20 Core language
Boost.Asio - Async network I/O
Boost.Program_options - CLI argument parsing
CMake 3.31+ Build system

Features

Core Functionality

  • Concurrent TCP connect scanning
  • Configurable thread count (default 100)
  • Port range and list support (e.g., 1-1024 or 80,443,8080)
  • Three port state detection: OPEN, CLOSED, FILTERED
  • Service banner grabbing for fingerprinting
  • Configurable connection timeout

Port State Detection

State Meaning TCP Response
OPEN Service listening SYN-ACK received
CLOSED Nothing listening, host responded RST received
FILTERED Firewall dropped packets silently Timeout (no response)

Security Relevance

  • First step in penetration testing reconnaissance
  • Attack surface mapping for security audits
  • Detecting unauthorized services and backdoors
  • Understanding TCP handshake mechanics

Architecture

main.cpp (CLI parsing with boost::program_options)
    ↓
┌─────────────────────────────────────────────┐
│            PortScanner Class                 │
│                                              │
│  ┌─────────────────────────────────────┐    │
│  │         Boost.Asio io_context       │    │
│  │  Thread pool (configurable count)   │    │
│  └──────────────────┬──────────────────┘    │
│                     │                        │
│  ┌──────────────────▼──────────────────┐    │
│  │     Async TCP Connect per port      │    │
│  │  - Connect attempt with timeout     │    │
│  │  - State detection (open/closed/    │    │
│  │    filtered)                         │    │
│  │  - Banner grab on success           │    │
│  └──────────────────┬──────────────────┘    │
│                     │                        │
│  ┌──────────────────▼──────────────────┐    │
│  │         Results Collection           │    │
│  │  Port | State | Service | Banner    │    │
│  └─────────────────────────────────────┘    │
└─────────────────────────────────────────────┘

Quick Start

cd PROJECTS/beginner/simple-port-scanner

# Build
mkdir build && cd build
cmake ..
make

# Scan localhost ports 1-1024
./simplePortScanner -i 127.0.0.1 -p 1-1024

# Scan specific ports with custom settings
./simplePortScanner -i scanme.nmap.org -p 80,443,8080 -t 50 -e 3

CLI Options

Flag Description Default
-i Target IP address Required
-p Port range or list Required
-t Thread count 100
-e Timeout (seconds) 3

Project Structure

simple-port-scanner/
├── src/
│   ├── PortScanner.hpp    # Class definition and method signatures
│   └── PortScanner.cpp    # Scanning logic, async operations, banner grabbing
├── main.cpp               # Entry point, CLI argument parsing
└── CMakeLists.txt         # Build configuration (Boost dependencies)

Build Requirements

  • CMake 3.31+
  • C++20 compiler (GCC 10+, Clang 12+, or MSVC 2019+)
  • Boost libraries (apt install libboost-all-dev or brew install boost)

Source Code

View on GitHub

Clone this wiki locally