A simple and efficient command-line port scanner written in Python. This tool supports both TCP Connect and SYN (stealth) scanning methods to identify open ports on a target host. Ideal for network administrators and security enthusiasts to perform basic network reconnaissance.
- π Dual Scan Modes: Choose between TCP Connect and SYN scanning
- π― Customizable Port Range: Specify any port range (1β65535)
- π‘οΈ Error Handling: Robust handling of invalid inputs, network errors, and user interruptions
- π Clean Output: Displays open ports and timestamps in a readable format
- β‘ Lightweight: Minimal dependencies, fast to install and run
- Python 3.6+
scapy
library (required for SYN scanning)- Root privileges (required for SYN scanning)
-
Clone the repository:
git clone https://github.com/NYXBAM/cli-port-scanner.git cd cli-port-scanner pip install -r requirements.txt
-
Usage
python3 portscanner.py <host> <start_port> <end_port> <syn_scan>
Arguments
host: Target IP address or hostname (e.g., 127.0.0.1 or example.com)
start_port: Starting port number (1β65535)
end_port: Ending port number (1β65535)
syn_scan: Scanning mode β use yes for SYN scan, no for TCP Connect scan
π§ Examples:
Scan ports 20β80 on localhost using TCP Connect:
python3 portscanner.py 127.0.0.1 20 80 no
Scan ports 20β80 on a remote host using SYN scan (requires root):
sudo python3 portscanner.py example.com 20 80 yes
π₯οΈ Sample Output:
Scanning host: 127.0.0.1
Scan started at: 2025-07-12 16:45:23.123456
--------------------------------------------------
Port 22: Open
Port 80: Open
--------------------------------------------------
Open ports: [22, 80]
Scan completed at: 2025-07-12 16:45:25.789012
SYN Scanning: Requires root privileges due to raw socket usage. Run with sudo when using --syn-scan yes.
Legal Warning: Port scanning without proper authorization may be illegal. Use this tool only on systems you own or are authorized to scan.
Performance: This is a single-threaded scanner for simplicity. For faster scanning, consider adding multithreading in future versions.
π€ Contributing
Contributions are welcome! Please open an issue or submit a pull request for bugs, features, or suggestions. π License
This project is licensed under the MIT License.