This Python script is a simple port scanner that can scan all ports, a specific range of ports, or specific ports on a target IP address. It also includes a verbose mode that provides detailed output for each port scanned.
Before using the script, make sure you have Python 3.x installed on your system.
Download the script: Save the script as app.py
.
Make the script executable (Optional, for Linux/Mac):
chmod +x app.py
You can use this script via the command line or terminal. The basic syntax is as follows:
python app.py -t <target_ip> -p <ports> [options]
-t, --target
(required): Target IP address to scan.-p, --ports
(required): Ports to scan. You can specify:
all
: Scan all 65,535 ports.start-end
: Scan a range of ports (e.g., 20-80
).port1,port2,...
: Scan specific ports (e.g., 22,80,443
).-v, --verbose
: Enable verbose output for detailed scanning information (e.g., connection attempts, errors).This command will scan all ports (1-65535) on the target IP 192.168.1.1
and print detailed messages for each port.
python app.py -t 192.168.1.1 -p all -v
Scanning 192.168.1.1...
[-] Port 1: CLOSED
[-] Port 2: CLOSED
[+] Port 22: OPEN
[+] Port 80: OPEN
...
Open ports on 192.168.1.1: [22, 80, 443]
This command will scan ports from 20
to 80
on the target IP 192.168.1.1
and print detailed messages.
python app.py -t 192.168.1.1 -p 20-80 -v
Scanning 192.168.1.1...
[-] Port 20: CLOSED
[+] Port 22: OPEN
[+] Port 80: OPEN
...
Open ports on 192.168.1.1: [22, 80]
This command will scan only ports 22
, 80
, and 443
on the target IP 192.168.1.1
and print only the list of open ports (no verbose output).
python app.py -t 192.168.1.1 -p 22,80,443
Scanning 192.168.1.1...
Open ports on 192.168.1.1: [22, 80, 443]
-v
), the script prints the status for each port being scanned (e.g., OPEN
, CLOSED
, or errors).