Skip to content

A basic Port Scanner software that sends request to every port, on the target, asking to connect to the network. The Port Scanner analyzes the responses to filter open ports.

Notifications You must be signed in to change notification settings

karangandhi-projects/Port-Scanner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

🔍 Python Port Scanner

Python License

A minimal command‑line port scanner written in pure Python. Give it one or more targets (IPv4 address or hostname), choose how many ports you want to probe, and the script will quickly report which ports are open and, when possible, grab the service banner.

✨ Features

  • Scan a single host or multiple hosts (comma‑separated) in one run
  • Banner grabbing – fetch up to 1 KB from open sockets to identify running services
  • Accepts hostnames or raw IP addresses (uses IPy to validate/convert)
  • Adjustable speed/accuracy – change the socket timeout to trade accuracy for speed
  • Zero external dependencies beyond IPy

🚀 Quick Start

# Clone the repo
$ git clone https://github.com/youruser/python-port-scanner.git
$ cd python-port-scanner

# (Optional) create a virtual environment
$ python -m venv .venv && source .venv/bin/activate

# Run the scanner
$ python port_scanner.py

You’ll be prompted for the target(s) and the number of ports to scan.

⚙️ Usage Examples

Scan the first 1000 ports of a single host

$ python port_scanner.py
[+] Enter target/s to scan (split multiple targets with ,): scanme.nmap.org
[+] Enter number of ports you want to scan: 1000

Scan multiple hosts

$ python port_scanner.py
[+] Enter target/s to scan (split multiple targets with ,): 192.168.1.10,example.com,10.0.0.5
[+] Enter number of ports you want to scan: 500

Tweak the timeout (edit scan_port)

If you need higher accuracy (at the cost of speed), increase the timeout:

sock.settimeout(1)  # default is 0.5 seconds

🗂️ Project Structure

python-port-scanner/
├── port_scanner.py      # main script (≈90 lines)
└── README.md            # you are here

🛠️ How It Works (High Level)

  1. Input parsing – Accept a single string of targets, split on commas, and normalise each to an IPv4 address with IPy/socket.gethostbyname().
  2. Port loop – For every port in range(1, n) create a TCP socket and attempt to connect().
  3. Timeout – Sockets time out after 0.5 s (configurable) to keep the scan quick.
  4. Banner grabbing – If a connection succeeds, attempt to recv(1024) bytes to capture the service banner.
  5. Output – Print [+] Open port {port}: {banner} or simply [+] Open port {port} if no banner is returned.

Because closed/filtered ports raise exceptions, they’re silently ignored to keep the output clean.

📋 Requirements

  • Python 3.7 or newer
  • IPy (install via pip)

👤 Author

Mohamed Ezzat – mohamedaezzat.github.io

I would highly recommend checking out his GitHub for learning material with hands-on projects

About

A basic Port Scanner software that sends request to every port, on the target, asking to connect to the network. The Port Scanner analyzes the responses to filter open ports.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages