Skip to content

Latest commit

 

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TCP Port & Service Scanner

Description

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.

How It Works

  1. The user enters a target IP address when running the script.
  2. The script uses the python-nmap library to run an Nmap scan against that IP.
  3. It filters the scan results down to TCP port data.
  4. 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).
  5. Results are printed to the terminal and saved into a scan_report.txt file for later reference.

Built With

  • Python 3
  • python-nmap (Python wrapper for the Nmap scanning engine)
  • Nmap

Development & Testing Environment

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.

Sample Result

Running this tool against a test target (Metasploitable2) identified 23 open TCP ports Scan output showing 23 open ports and services, 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.

Use Case

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.

What I Learned

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.

How to Run

python3 scanner.py

You'll be prompted to enter a target IP address. The script will scan it and generate a scan_report.txt file with the results.

About

Scans a target IP using Nmap to identify open TCP ports and running services.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages