A simple yet effective command-line-based Port Scanner built in Python. This tool allows users to scan a target host to identify open ports in the range of 0–1023. The script is beginner-friendly and demonstrates fundamental concepts of network programming and socket communication in Python.
- User-Friendly Interface: Displays a banner using the
pyfiglet
library. - Target Scanning: Accepts a target IP address and scans ports from 0 to 1023.
- Real-Time Updates: Shows scanning progress and lists open ports in real-time.
- Error Handling: Handles exceptions gracefully for scenarios like invalid IP, hostname resolution issues, or user interruptions.
- Timestamp Tracking: Logs the start and end time of the scanning process for time tracking.
- Python 3.8+
- Libraries:
pyfiglet
socket
Install the required dependencies using:
pip install pyfiglet
- Clone or download this repository.
git clone https://github.com/d3vda5/port-scanner.git
- Open a terminal and navigate to the folder containing
Port_Scanner.py
.
cd port-scanner
- Run the script with the following command:
python Port_Scanner.py <target_IP>
Replace <target_IP>
with the IP address of the target you want to scan.
python Port_Scanner.py 192.168.1.1
PORT SCANNER
--------------------------------------------------
Scanning Target: 192.168.1.1
Scanning started at: 2025-01-17 14:00:00
--------------------------------------------------
Port 80 is open
Port 443 is open
...
--------------------------------------------------
Scanning ended at: 2025-01-17 14:00:15
Total Scanning time: 15 seconds
Port_Scanner.py
: The main script for scanning ports on the target host.
- The script accepts a target IP address as a command-line argument.
- Resolves the hostname to ensure it's valid.
- Iterates through ports 0–1023, attempting to establish a connection using the
socket
library. - If a connection is successful, the port is marked as open.
- Displays the open ports and the total scanning time at the end.
- Invalid Arguments: Prompts the user if the IP address is missing.
- Hostname Resolution Error: Notifies if the hostname cannot be resolved.
- Socket Error: Informs if the server is unresponsive.
- Keyboard Interrupt: Safely exits the program if interrupted by the user.
- The script currently scans only well-known ports (0–1023). For a broader scan, adjust the
range()
function in the code. - This scanner is meant for educational and authorized use only. Unauthorized scanning of systems is illegal and unethical.
- Add support for custom port ranges.
- Enable multi-threaded scanning for faster results.
- Enhance the output format for better readability.
- Include advanced features like service detection and protocol analysis.
This tool is intended for educational purposes only. Ensure you have proper authorization before scanning any target.