Projects · 03/06

Projects

TCP port scanner

A compact TCP connect scanner in C that walks every port from 1 to 65535 on localhost using BSD sockets, with 100 ms timeouts and a final tally of open gates.

cd ..back to projects

Overview

A single-file exercise in raw socket programming. For each port the scanner opens a socket, sets send and receive timeouts with setsockopt, attempts connect(), reports open ports and closes the descriptor. Progress is printed every 5000 ports and a summary at the end. It is intentionally small: a study of the POSIX socket API rather than a replacement for nmap.

Highlights

  • Full range scan with bounded per-port latency via SO_RCVTIMEO and SO_SNDTIMEO.
  • Roughly sixty lines, no dependencies beyond the C standard library and POSIX headers.