A fast, multi-threaded TCP port scanner built in Python. Scans a target host for open ports and identifies common services running on them.
⚠️ Disclaimer: This tool is built for educational purposes and authorized security testing only. Scanning networks or systems without explicit permission is illegal in most countries, including Pakistan under the Prevention of Electronic Crimes Act (PECA) 2016. Only use this on systems you own or have written permission to test.
- Multi-threaded scanning for speed (100 threads by default)
- Custom port range support
- Common service name mapping (FTP, SSH, HTTP, MySQL, RDP, etc.)
- Optional banner grabbing (
-v) to identify service versions - Save results to a file (
-o) - Simple command-line interface
- Python 3.7+
- No external libraries needed (uses Python's built-in
socket,threading, andargparsemodules)
Clone the repository:
git clone https://github.com/rayan-407/Port-Scanner.git
cd Port-ScannerRun a basic scan:
python3 port_scanner.py 127.0.0.1| Flag | Description | Example |
|---|---|---|
-p, --ports |
Port range to scan | -p 1-500 |
-t, --threads |
Number of threads | -t 200 |
--timeout |
Socket timeout (seconds) | --timeout 1 |
-v, --verbose |
Grab service banners | -v |
-o, --output |
Save results to file | -o results.txt |
python3 port_scanner.py 192.168.1.1 -p 1-1024 -v -o results.txtSample output:
===================================================
Scanning target : 192.168.1.1 (192.168.1.1)
Port range : 1-1024
Threads : 100
Started at : 2026-07-22 21:40:11.421122
===================================================
[+] Port 80 OPEN (HTTP)
[+] Port 443 OPEN (HTTPS)
===================================================
Scan completed at : 2026-07-22 21:40:17.070777
Total open ports : 2
===================================================
[+] Results saved to results.txt
The scanner uses Python's socket module to attempt a TCP connection to each port in the specified range. If the connection succeeds (connect_ex() returns 0), the port is marked open. Multiple threads run concurrently via a Queue, which significantly speeds up scanning large port ranges.
- UDP port scanning support
- Export results in JSON/CSV format
- Progress bar for large scans
- Integration with a simple vulnerability database
This project is licensed under the MIT License - see the LICENSE file for details.
Rayan - Cybersecurity enthusiast learning through hands-on projects.
Check out my other project: Password Strength Checker