Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

PortScanner

A simple TCP Port Scanner built in C++17 for Windows, using Winsock2. Built for learning networking concepts and CTF (Capture The Flag) recon.

Features

  • Scans a range of TCP ports on a target IP
  • Uses non-blocking sockets with configurable timeout
  • Identifies common well-known services (SSH, HTTP, HTTPS, SMB, MySQL, etc.)
  • Clean summary output with open ports and scan duration

Project Structure

PortScanner/
├── include/
│   └── Scanner.hpp
├── src/
│   ├── Scanner.cpp
│   └── main.cpp
├── data/
└── README.md

Requirements

  • Windows
  • g++ (MinGW) with C++17 support

Build

g++ -std=c++17 -o portscanner src/main.cpp src/Scanner.cpp -I include/ -lws2_32

Usage

portscanner.exe <IP> <start_port> <end_port> [timeout_ms]

Examples

portscanner.exe 127.0.0.1 1 1024
portscanner.exe 192.168.1.1 1 1024 200

timeout_ms is optional (default: 500ms). Lower it for faster scans.

Sample Output

[*] Target  : 127.0.0.1
[*] Range   : 1 - 1024
[*] Timeout : 500 ms

  [OPEN]  Port   135  ->  MS-RPC
  [OPEN]  Port   445  ->  SMB

+===========================================+
|         SCAN RESULTS SUMMARY             |
+===========================================+
|  Target  : 127.0.0.1                     |
|  Scanned : 1024                          |
|  Open    : 2                             |
+===========================================+
|  PORT     STATE   SERVICE                |
+===========================================+
|  135      OPEN    MS-RPC                   |
|  445      OPEN    SMB                      |
+===========================================+

How It Works

The scanner performs a TCP connect scan on each port in the given range:

  1. Opens a non-blocking TCP socket
  2. Attempts to connect to the target IP and port
  3. Waits for the connection result within the given timeout using select()
  4. Marks the port as open if the connection succeeds, closed otherwise

Disclaimer

This tool is for educational purposes and authorized testing only. Do not scan systems you don't own or don't have explicit permission to test.

License

MIT

About

Educational TCP Port Scanner - Winsock2 Socket Programming | C++17

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages