Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

🔍 Python Port Scanner

A fast, multi-threaded TCP port scanner built in Python. Scans a target host for open ports and identifies common services running on them.

⚠️ Disclaimer: This tool is built for educational purposes and authorized security testing only. Scanning networks or systems without explicit permission is illegal in most countries, including Pakistan under the Prevention of Electronic Crimes Act (PECA) 2016. Only use this on systems you own or have written permission to test.


✨ Features

  • Multi-threaded scanning for speed (100 threads by default)
  • Custom port range support
  • Common service name mapping (FTP, SSH, HTTP, MySQL, RDP, etc.)
  • Optional banner grabbing (-v) to identify service versions
  • Save results to a file (-o)
  • Simple command-line interface

🛠️ Requirements

  • Python 3.7+
  • No external libraries needed (uses Python's built-in socket, threading, and argparse modules)

🚀 Usage

Clone the repository:

git clone https://github.com/rayan-407/Port-Scanner.git
cd Port-Scanner

Run a basic scan:

python3 port_scanner.py 127.0.0.1

Options

Flag Description Example
-p, --ports Port range to scan -p 1-500
-t, --threads Number of threads -t 200
--timeout Socket timeout (seconds) --timeout 1
-v, --verbose Grab service banners -v
-o, --output Save results to file -o results.txt

Example

python3 port_scanner.py 192.168.1.1 -p 1-1024 -v -o results.txt

Sample output:

===================================================
Scanning target : 192.168.1.1 (192.168.1.1)
Port range      : 1-1024
Threads         : 100
Started at      : 2026-07-22 21:40:11.421122
===================================================
[+] Port 80     OPEN   (HTTP)
[+] Port 443    OPEN   (HTTPS)
===================================================
Scan completed at : 2026-07-22 21:40:17.070777
Total open ports  : 2
===================================================
[+] Results saved to results.txt

📚 How It Works

The scanner uses Python's socket module to attempt a TCP connection to each port in the specified range. If the connection succeeds (connect_ex() returns 0), the port is marked open. Multiple threads run concurrently via a Queue, which significantly speeds up scanning large port ranges.


🔮 Future Improvements

  • UDP port scanning support
  • Export results in JSON/CSV format
  • Progress bar for large scans
  • Integration with a simple vulnerability database

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


👤 Author

Rayan - Cybersecurity enthusiast learning through hands-on projects.

Check out my other project: Password Strength Checker

About

A multi-threaded TCP port scanner built in Python.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages