This tool uses Nmap to scan a given IP address and identify the state of each TCP port, along with the service running on it. Instead of manually running Nmap commands and filtering the output by hand, this script automates the process into a single reusable tool: you enter an IP address, and it returns a clean, readable report of open ports and their services.
- The user enters a target IP address when running the script.
- The script uses the
python-nmaplibrary to run an Nmap scan against that IP. - It filters the scan results down to TCP port data.
- For each TCP port found, it looks up the port's state (open/closed) and the service running on it (e.g. ssh, http, ftp).
- Results are printed to the terminal and saved into a
scan_report.txtfile for later reference.
- Python 3
- python-nmap (Python wrapper for the Nmap scanning engine)
- Nmap
Built and tested using a Kali Linux VM (running the script) against a Metasploitable2 VM (an intentionally vulnerable target machine), both set up in VirtualBox for safe, isolated testing.
Running this tool against a test target (Metasploitable2) identified 23 open TCP ports
, including services such as FTP, SSH, Telnet, HTTP, MySQL, PostgreSQL, and VNC. This demonstrates how many services can be exposed on an unhardened system, and why regularly auditing open ports matters.
This tool is intended as an auditing tool, allowing an individual, security team, or organization to quickly check which ports are open on a system they own or are authorized to test, so unnecessary or risky services can be identified and closed before they can be exploited.
Note: This tool should only be used on systems you own or have explicit permission to scan. Scanning systems without authorization may be illegal.
This was my first Python project, built during my holidays after completing my first year of a BSc Cybersecurity degree (with a Java-based first year, and no prior programming background; I came from a premedical academic path). While building this, I learned:
- How to use Python to automate a real security tool (Nmap) instead of running commands manually.
- How to navigate nested dictionaries, the trickiest concept in this project, since Nmap's scan results are structured in multiple layers (host to protocol to port to detail).
- How to write functions that take parameters, so the scanner can be reused against any target IP rather than a fixed one.
- How to read from and write to files in Python, to generate a persistent report.
python3 scanner.pyYou'll be prompted to enter a target IP address. The script will scan it and generate a scan_report.txt file with the results.