Skip to content

Lek-glitch/python-port-scanner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Python Multithreaded Port Scanner

A lightweight command-line port scanner written in Python. It scans a target host over a given range of ports, reports which ones are open, and identifies the likely service running on common ports.

Why I Built This

To understand how network reconnaissance tools work at a fundamental level — how TCP connections are established, how scanners like Nmap work under the hood, and how to write clean, multithreaded Python for performance. This is a core skill for network security and SOC analyst roles.

Features

  • Scans any port range (e.g. 1-1024 or a single port)
  • Multithreaded for fast scanning
  • Identifies common services (SSH, HTTP, RDP, MySQL, etc.)
  • Configurable timeout and thread count
  • Clean, readable terminal output

Technologies Used

  • Python 3
  • socket (standard library)
  • threading and queue (standard library)
  • argparse for CLI arguments

How to Run

git clone https://github.com/yourusername/python-port-scanner.git
cd python-port-scanner
python port_scanner.py -t 127.0.0.1 -p 1-1024

Arguments

Flag Description Default
-t, --target Target IP or hostname (required)
-p, --ports Port range, e.g. 1-1024 or 80 1-1024
--timeout Socket timeout in seconds 1.0
--threads Number of worker threads 100

Sample Output

===================================================
 Scanning target : 127.0.0.1
 Port range      : 1-1024  (1024 ports)
 Started at      : 2026-07-08 10:15:03
===================================================
[+] Port    22 OPEN   (SSH)
[+] Port    80 OPEN   (HTTP)
===================================================
 Scan complete. 2 open port(s) found: [22, 80]
 Finished at     : 2026-07-08 10:15:05
===================================================

⚠️ Legal / Ethical Notice

This tool is for educational purposes only. Only scan systems you own or have explicit written permission to test (e.g. scanme.nmap.org, which is provided by the Nmap project specifically for testing). Scanning networks without authorization is illegal in most countries under laws like the Computer Fraud and Abuse Act (US) or equivalent legislation elsewhere.

What I Learned

  • How TCP three-way handshakes work and how connect_ex() detects open ports
  • How to use Python threading and queues to avoid slow, sequential scans
  • How to structure a CLI tool with argparse
  • The ethical and legal boundaries of network scanning

Future Improvements

  • Add UDP scanning support
  • Add banner grabbing to identify service versions
  • Export results to JSON/CSV
  • Add a simple GUI

About

Network auditing tool built in python to discover open ports, grab service banners, and map attack surfaces.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages