A simple but effective Python-based port scanner that detects open TCP ports on a host.
Inspired by tools like Nmap, this project demonstrates the fundamentals of network enumeration and cybersecurity.
- Multi-threaded scanning for faster results
- Detects open TCP ports in a given range
- Maps ports to common services (e.g.,
22 โ ssh,3306 โ mysql) - Built-in timeout handling (avoids freezing on closed/filtered ports)
- Tested safely on:
- Localhost
- Docker containers (e.g., MariaDB on port 3306)
- Public test host
scanme.nmap.org
The scanner uses Pythonโs built-in socket module to:
- Create a TCP socket for each port
- Attempt a connection to the target host and port
- Return
openif the connection succeeds within a given timeout - Look up the associated service name (if available)
Concurrency is handled using Pythonโs threading library, allowing multiple ports to be scanned simultaneously.
python3 scanner.py <start_port> <end_port>
python3 scanner.py localhost 3300 3400
Output: ๐ Scanning localhost from port 3300 to 3400...
[+] Port 3306 is open (mysql)
โ Scan complete!
python3 scanner.py scanme.nmap.org 20 1000
- Your own machine (
localhost) - Local test environments (e.g., Docker containers)
- Approved test servers like
scanme.nmap.org
Never scan random websites or servers without explicit permission.
- Networking fundamentals (TCP/IP, ports, sockets)
- Writing Python scripts with error handling and timeouts
- Using threads for concurrent execution
- Safe penetration testing practices using controlled environments
- Add process lookup to show which program is bound to an open port
- Implement UDP scanning in addition to TCP
- Add an option for output reports (JSON, CSV, HTML)
- Include a progress bar / fancy CLI UI for better user experience
- Compare results automatically with
nmapfor validation