This code is purely meant for learning purposes, and not meant to be used with malicious intent.
Python Project - This CLI tool allows the user to scan specified ports of a host.
Modules Used: 1. optparse - to enable command-line arguments in the terminal and their parsing 2. socket - to interact with the host and their ports
This CLI tool allows the user to scan specified ports of a host, and can be run in a terminal. The user can enter the host's IP address, and the port numbers (separated by comma - do not include any whitespace between commas and numbers). The tool scans ports one by one and returns a summary of findings for each port.
- Imported required libraries.
- Set up the arguments for the tool using optparse (-H/--Host and -p/--port).
- Read the user input, and parse them accordingly.
- Stored the host IP in a variable, and port numbers in a list.
- Wrote function for sending a message to a port and checking its response.
- Wrote a function to iterate through the list of port numbers, and initiate the above scan function for each port.
On using the help option, we get the following output:
Usage: port-scanner.py [options]
Options:
-h, --help show this help message and exit
-H TGHOST, --Host=TGHOST
specify target host
-p TGPORT, --port=TGPORT
specify target port[s] separated by comma
After entering a valid IP address for certifiedhacker.com and 3 ports - namely 21, 22, 80, the following output is displayed:
[+] Scan Results for: box5331.bluehost.com
Scanning port 21
[+] 21/tcp open
[+] 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 5 of 150 allo
Scanning port 22
[+] 22/tcp open
[+] SSH-2.0-OpenSSH_7.4
Protocol mismatch.
Scanning port 80
[+] 80/tcp open
[+] HTTP/1.1 400 Bad Request
Date: Sat, 14 Sep 2024 06:07:12 GMT
Server: Apache
Content-Length: 347
Shreelu Santosh
GitHub Profile