Skip to content

A complete, self-contained Python script called port_scanner.py. This version uses threading to scan ports concurrently, making the process much faster than scanning one port at a time.

Notifications You must be signed in to change notification settings

Takurus/port_scanner.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ” Python Simple Port and Service Scanner This project is a fast, multi-threaded TCP port scanner written in pure Python. It is designed to quickly identify open ports on a target host (IP or hostname) and attempt to determine the standard service running on that port.

๐Ÿ›ก๏ธ Cybersecurity Note DO NOT use this tool to scan networks or hosts you do not own or have explicit permission to test. Port scanning without authorization is illegal and unethical. For testing, you can safely use public targets like scanme.nmap.org.

๐Ÿš€ Features Multi-threading: Uses the concurrent.futures.ThreadPoolExecutor to perform concurrent scans, significantly reducing the time required to check large port ranges.

IP Resolution: Automatically resolves hostnames (e.g., google.com) into IP addresses.

Service Identification: Attempts to look up the common service name (e.g., http, ssh) associated with an open port.

Flexible Input: Supports scanning single ports, ranges (e.g., 1-100), or comma-separated lists (e.g., 21,22,80).

โš™๏ธ Getting Started Prerequisites This project requires only the standard Python installation and no external libraries.

Python 3.6+

Running the Scanner Save the code as port_scanner.py.

Run the script from your terminal:

python port_scanner.py

Follow the prompts:

Enter the target IP or hostname: Input the address you wish to scan (e.g., 192.168.1.1 or scanme.nmap.org).

Enter port range: Specify the ports to check (e.g., 1-100, 80,443,8080).

๐Ÿ› ๏ธ Configuration Details The performance and reliability of the scanner can be tuned by modifying the constants at the top of the port_scanner.py file:

Constant

Default Value

Description

socket.setdefaulttimeout

0.5 seconds

Sets the time the scanner waits for a response from a port before concluding it's closed. Lowering this value makes the scan faster but may cause it to miss slower-responding open ports.

MAX_THREADS

100

The maximum number of concurrent threads used for scanning. Increasing this can make the scan faster but may overload your network or be blocked by firewalls.

๐Ÿ“ Example Output *** Python Simple Port and Service Scanner *** Enter the target IP or hostname (e.g., scanme.nmap.org): scanme.nmap.org Enter port range (e.g., 1-100 or 80,443): 20-30

[INFO] Starting scan on target: 45.33.32.179 [INFO] Scanning 11 ports using up to 100 threads... [+] Port 22 is OPEN | Service: ssh [+] Port 25 is OPEN | Service: smtp

--- SCAN SUMMARY --- [SUCCESS] Open Ports: [22, 25] [INFO] Total Ports Scanned: 11 [INFO] Time Elapsed: 1.55 seconds

About

A complete, self-contained Python script called port_scanner.py. This version uses threading to scan ports concurrently, making the process much faster than scanning one port at a time.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages