A lightweight command-line port scanner written in Python. It scans a target host over a given range of ports, reports which ones are open, and identifies the likely service running on common ports.
To understand how network reconnaissance tools work at a fundamental level — how TCP connections are established, how scanners like Nmap work under the hood, and how to write clean, multithreaded Python for performance. This is a core skill for network security and SOC analyst roles.
- Scans any port range (e.g.
1-1024or a single port) - Multithreaded for fast scanning
- Identifies common services (SSH, HTTP, RDP, MySQL, etc.)
- Configurable timeout and thread count
- Clean, readable terminal output
- Python 3
socket(standard library)threadingandqueue(standard library)argparsefor CLI arguments
git clone https://github.com/yourusername/python-port-scanner.git
cd python-port-scanner
python port_scanner.py -t 127.0.0.1 -p 1-1024| Flag | Description | Default |
|---|---|---|
-t, --target |
Target IP or hostname (required) | — |
-p, --ports |
Port range, e.g. 1-1024 or 80 |
1-1024 |
--timeout |
Socket timeout in seconds | 1.0 |
--threads |
Number of worker threads | 100 |
===================================================
Scanning target : 127.0.0.1
Port range : 1-1024 (1024 ports)
Started at : 2026-07-08 10:15:03
===================================================
[+] Port 22 OPEN (SSH)
[+] Port 80 OPEN (HTTP)
===================================================
Scan complete. 2 open port(s) found: [22, 80]
Finished at : 2026-07-08 10:15:05
===================================================
This tool is for educational purposes only. Only scan systems you own or have explicit written permission to test (e.g. scanme.nmap.org, which is provided by the Nmap project specifically for testing). Scanning networks without authorization is illegal in most countries under laws like the Computer Fraud and Abuse Act (US) or equivalent legislation elsewhere.
- How TCP three-way handshakes work and how
connect_ex()detects open ports - How to use Python threading and queues to avoid slow, sequential scans
- How to structure a CLI tool with
argparse - The ethical and legal boundaries of network scanning
- Add UDP scanning support
- Add banner grabbing to identify service versions
- Export results to JSON/CSV
- Add a simple GUI