Our Latest Articles

Ethical Hacking Mini Project Tutorial for Beginners

Build a Python Port Scanner: Ethical Hacking Mini Project Tutorial for Beginners

June 05, 20264 min read

Ethical Hacking Mini Project: Build a Python Port Scanner from Scratch

One of the first skills every aspiring ethical hacker should learn is network reconnaissance. Before security professionals can identify vulnerabilities, they must first understand which systems, services, and ports are exposed on a network.

Port scanning is a fundamental technique used during the reconnaissance phase of ethical hacking and penetration testing. It helps security professionals discover open ports and running services on target systems.

In this hands-on tutorial, you will build a simple Python-based Port Scanner from scratch. This project is beginner-friendly and will help you understand networking concepts, socket programming, and ethical hacking fundamentals.

Important Note: Only scan systems that you own or have explicit permission to test.


What is a Port Scanner?

A port scanner is a tool that checks whether specific network ports on a device are open, closed, or filtered.

Common examples include:

  • Nmap

  • Masscan

  • Angry IP Scanner

By creating your own port scanner, you'll understand how these tools work behind the scenes.


Project Objectives

By completing this project, you will learn:

  • TCP/IP Networking Basics

  • Socket Programming

  • Open Port Detection

  • Python Fundamentals

  • Ethical Hacking Reconnaissance Techniques


Prerequisites

Before starting, make sure you have:

Software

  • Python 3.x

  • VS Code or any Python IDE

  • Internet Connection

Knowledge

  • Basic Python

  • Basic Networking Concepts

  • IP Addresses

  • Ports


Understanding Ports

Ports allow applications to communicate over networks.

Examples:

PortService21FTP22SSH25SMTP53DNS80HTTP443HTTPS

When a port is open, a service is actively listening for connections.


Project Architecture

User Inputs Target IP ↓
Python Scanner ↓
Checks Port Availability ↓
Reports Open Ports

Step 1: Create Project Folder

Create a folder named:

PortScannerProject

Inside it create:

port_scanner.py

Step 2: Import Required Libraries

Open the Python file and add:

import socket

Why Socket?

The socket module allows Python to communicate using network protocols.


Step 3: Get Target IP Address

Add:

target = input("Enter Target IP Address: ")

Example:

192.168.1.1

Step 4: Create Port Scanning Function

Add:

def scan_port(ip, port): try: sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) sock.settimeout(1) result = sock.connect_ex((ip, port)) if result == 0: print(f"Port {port} is OPEN") sock.close() except: pass

What Happens Here?

  • Creates TCP socket

  • Attempts connection

  • Checks if connection succeeds

  • Displays open ports


Step 5: Scan Common Ports

Add:

print(f"Scanning {target}...") for port in range(1, 1025): scan_port(target, port)

This scans ports:

1 → 1024

These are commonly used service ports.


Step 6: Complete Program

Final code:

import socket target = input("Enter Target IP Address: ") def scan_port(ip, port): try: sock = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) sock.settimeout(1) result = sock.connect_ex((ip, port)) if result == 0: print(f"Port {port} is OPEN") sock.close() except: pass print(f"Scanning {target}...") for port in range(1, 1025): scan_port(target, port)

Step 7: Run the Scanner

Execute:

python port_scanner.py

Example:

Enter Target IP Address:
127.0.0.1

Output:

Scanning 127.0.0.1 Port 80 is OPEN
Port 443 is OPEN
Port 3306 is OPEN

Understanding the Results

Open Port

A service is actively listening.

Closed Port

No service is listening.

Filtered Port

Firewall may be blocking access.


Security Applications

Ethical hackers use port scanning to:

  • Discover exposed services

  • Identify attack surfaces

  • Map network infrastructure

  • Verify firewall configurations

System administrators use it to:

  • Audit security

  • Monitor services

  • Troubleshoot networks


Enhancing the Project

After building the basic scanner, add:

Multi-threading

Scan faster.

Service Detection

Identify running services.

Example:

Port 80 → HTTP
Port 22 → SSH

Banner Grabbing

Retrieve service information.

GUI Interface

Build using Tkinter.

Export Reports

Generate CSV reports.


Real-World Tools Using Similar Concepts

Professional tools built on similar principles include:

  • Nmap

  • Zenmap

  • Masscan

  • Nessus

  • OpenVAS

Understanding your own scanner helps you understand these professional tools.


Skills Demonstrated in This Project

Add these to your resume:

Networking

  • TCP/IP

  • Ports

  • Services

Python

  • Functions

  • Loops

  • Error Handling

Cybersecurity

  • Reconnaissance

  • Port Scanning

  • Network Enumeration


Portfolio Documentation

When publishing this project on GitHub, include:

Project Overview

Purpose of the scanner.

Screenshots

Terminal output.

Features

  • Open port detection

  • Fast scanning

  • Simple interface

Future Enhancements

Planned improvements.


Learning Outcomes

After completing this mini-project, you will understand:

  • How networks communicate

  • How TCP connections work

  • How ethical hackers discover services

  • Basic socket programming

  • Python-based security automation

This project forms an excellent foundation for advanced cybersecurity topics such as vulnerability scanning, network mapping, penetration testing, and ethical hacking.


Next Projects to Build

After this project, consider:

  1. Network Scanner

  2. Banner Grabber

  3. Password Strength Checker

  4. Vulnerability Scanner

  5. Wireshark Packet Analysis Project

  6. Web Application Security Scanner

Each project will progressively strengthen your ethical hacking and cybersecurity skills.

Final Thoughts

Building your own port scanner is one of the best beginner cybersecurity projects because it combines networking, Python programming, and ethical hacking concepts into a practical, real-world application.

The goal isn't just to create a tool—it is to understand the concepts behind reconnaissance and network security. As you continue your cybersecurity journey, this knowledge will become the foundation for more advanced penetration testing and ethical hacking techniques.

python port scanner projectethical hacking mini projectcybersecurity project for beginnerspython ethical hacking projectport scanner tutorialnetwork security projectcybersecurity portfolio projectethical hacking projectspython socket programmingpenetration testing beginner projectcybersecurity hands on projectpython networking projectcybersecurity learning projectethical hacking tutorialnetwork scanning project
Back to Blog

Empowering learners worldwide to master AI through accessible, high-quality learning.

Newsletter

Get AI career insights, learning resources, project updates, certifications, and future-ready tech guidance directly in your inbox.