I built this project to get comfortable with Python's socket library and to understand how network connections work under the hood. It started as a basic script and I've been refactoring it to make it faster and more efficient.
- Scans a range of TCP ports on a target IP address.
- Uses multithreading (ThreadPoolExecutor) to scan ports in parallel (much faster than a basic loop).
- Identifies your own public IP for testing purposes.
-
Clone the repo: git clone https://github.com/devogabs/python-port-scanner.git cd python-port-scanner
-
Install dependencies: pip install -r requirements.txt
-
Run the scanner: python src/scanner.py
- Sockets: I learned how the TCP three-way handshake works and how
connect_exreturns error codes instead of crashing the program. - Concurrency: My first version was very slow. I learned how to use
ThreadPoolExecutorto handle hundreds of port checks at the same time. - Lambda Functions: I used lambdas to pass arguments into my threaded functions—which was confusing at first, but makes the code a lot cleaner.
- Add a SYN scan (stealth scan) using Scapy.
- Add the ability to export results to a .csv file.
- Implement a GUI or a more robust CLI with
argparse.
Disclaimer: This tool is for educational purposes only. Do not use it to scan networks you do not own or have explicit permission to test.