This script is an advanced port scanner designed to identify open, closed, and filtered ports on one or more specified targets. It supports various scanning techniques, including TCP, UDP, and SYN scans, and offers advanced features such as service version detection, OS detection, distributed scanning, and machine learning-based data analysis.
- TCP, UDP, and SYN Scanning: Support for different types of port scanning.
- Service Version Detection: Detect the version of services running on open ports.
- OS Detection: Attempt to detect the target's operating system.
- Distributed Scanning: Scan using multiple workers to increase speed.
- Machine Learning Analysis: Analyze scan data to identify suspicious patterns and predict potential attacks.
- Tor Support: Use Tor for anonymous scanning.
- Alerting: Send alerts via email or webhook.
- IoT Device Identification: Identify IoT devices based on open ports.
- Vulnerability Assessment: Evaluate vulnerabilities in IoT devices and open ports.
- Scheduled Scans: Perform scans at regular intervals.
- Encryption: Encrypt scan results before saving or sending.
- Historical Reports: Generate reports based on past scan results.
- Website Vulnerability Scanning: Scan websites for common vulnerabilities such as SQL Injection, XSS, and more.
-
Ensure you have Python 3.7 or higher installed. Then, install the required libraries:
pip install -r requirements.txt
OR
pip install --break-system-packages -r requirements.txt
- The script is executed via the command line and supports numerous options. Below are some commands and examples:
- To scan a target with the default port range (1-1024):
python main.py 192.168.1.1
- To scan a target with a specific port range:
python main.py 192.168.1.1 -p 1-1000
- To scan with a specific type (e.g., UDP):
python main.py 192.168.1.1 -t udp
- To scan with service version detection:
python main.py 192.168.1.1 -V
- To scan with OS detection:
python main.py 192.168.1.1 -O
- To perform a distributed scan using multiple workers:
python main.py 192.168.1.1 --distributed 192.168.1.2,192.168.1.3
- To perform an anonymous scan using Tor:
python main.py 192.168.1.1 --use-tor
- To send alerts via email or webhook:
python main.py 192.168.1.1 --send-alerts
- To identify IoT devices:
python main.py 192.168.1.1 --identify-iot-devices
- To evaluate IoT device vulnerabilities:
python main.py 192.168.1.1 --evaluate-iot-vulnerabilities
- To perform machine learning-based data analysis:
python main.py 192.168.1.1 --advanced-analysis
- To perform a rate-limited scan (e.g., 10 requests per second):
python main.py 192.168.1.1 --rate-limit 10
- To save scan results to a file:
python main.py 192.168.1.1 -o results.json
- To generate charts from scan results:
python main.py 192.168.1.1 --generate-charts
- To perform a scheduled scan (e.g., every hour):
python main.py 192.168.1.1 --schedule 1h
- To identify open management ports:
python main.py 192.168.1.1 --identify-management-ports
- To identify insecure configuration files:
python main.py 192.168.1.1 --identify-insecure-configs
- To check encryption protocols (SSH, HTTPS, TLS):
python main.py 192.168.1.1 --check-encryption
- To check the Modbus protocol:
python main.py 192.168.1.1 --check-modbus
- To check the MQTT protocol:
python main.py 192.168.1.1 --check-mqtt
- To check the CoAP protocol:
python main.py 192.168.1.1 --check-coap
- To compare current scan results with a previous scan:
python main.py 192.168.1.1 --compare-previous
- To generate a historical report based on past scans:
python main.py 192.168.1.1 --generate-historical-report
- To scan a website for common vulnerabilities:
python main.py http://example.com --scan-website
| Option | Description |
|---|---|
targets |
Target IP addresses (comma-separated or CIDR) |
-p, --ports |
Port range (e.g., 1-100) or specific ports (e.g., 80,443) |
-t, --type |
Scan type (tcp, udp, syn) |
-T, --timeout |
Timeout for each scan (in seconds) |
-m, --max-threads |
Maximum number of threads |
-O, --os-detection |
Enable OS detection |
-V, --version-detection |
Enable service version detection |
-o, --output |
Output file to save results (supports .txt, .json, .csv, .xml, .html, .pdf) |
-i, --input |
Input file containing a list of targets (one per line) |
-r, --rate-limit |
Rate limit in requests per second |
--random-scan |
Scan ports in random order |
--priority-scan |
Scan common ports first |
--country-filter |
Filter targets by country code (e.g., US, IR) |
--custom-scan |
Custom scan type (xmas, fin, null) |
--discover-local |
Discover local devices (IPv4 and IPv6) |
--traceroute |
Perform traceroute to the target |
--distributed |
Enable distributed scanning (comma-separated list of workers) |
--async-scan |
Enable asynchronous scanning |
--filter-ports |
Filter ports to scan (e.g., 80,443) |
--filter-protocols |
Filter protocols to scan (e.g., tcp,udp) |
--generate-charts |
Generate charts for scan results |
--use-tor |
Use Tor for anonymity |
--encrypt-data |
Encrypt data before saving or sending |
--config |
Load scan settings from a config file |
--schedule |
Schedule scans at specific intervals (e.g., 1h for hourly) |
--vulnerability-scan |
Enable vulnerability scanning |
--check-default-files |
Check for default or insecure files |
--check-crypto |
Check for crypto vulnerabilities |
--advanced-analysis |
Enable advanced data analysis with machine learning |
--detect-suspicious-traffic |
Detect suspicious traffic patterns |
--load-test |
Perform a load test on a specific port |
--evaluate-capacity |
Evaluate server capacity under high traffic |
--check-modbus |
Check Modbus protocol on the target |
--check-mqtt |
Check MQTT protocol on the target |
--check-coap |
Check CoAP protocol on the target |
--check-encryption |
Check encryption protocols (SSH, HTTPS, TLS) on the target |
--identify-vulnerable-ports |
Identify vulnerable ports |
--identify-insecure-configs |
Identify insecure configuration files |
--identify-management-ports |
Identify open management ports |
--threat-intelligence |
Check IPs against local threat intelligence |
--send-alerts |
Send alerts via email or webhook |
--identify-iot-devices |
Identify IoT devices |
--evaluate-iot-vulnerabilities |
Evaluate IoT vulnerabilities |
--compare-previous |
Compare current scan results with a previous scan |
--generate-historical-report |
Generate a historical report based on past scans |
--scan-website |
Scan a website for vulnerabilities |
-
Scan a Target with Port Range 1-1000 and Save Results to JSON:
python main.py 192.168.1.1 -p 1-1000 -o results.json
-
Distributed Scan Using Two Workers:
python main.py 192.168.1.1 --distributed 192.168.1.2,192.168.1.3
-
Scan with Service Version and OS Detection:
python main.py 192.168.1.1 -V -O
-
Scan Using Tor and Send Alerts:
python main.py 192.168.1.1 --use-tor --send-alerts
-
Scheduled Scan Every Hour:
python main.py 192.168.1.1 --schedule 1h
-
Port Scanning Functions:
scan_tcp_port(ip: str, port: int, timeout: int = 1, version_detection: bool = False, os_detection: bool = False):- Scans a TCP port on the target IP.
- Optionally detects service version and OS.
- Returns a tuple containing the port, status (open/closed), and service.
scan_udp_port(ip: str, port: int, timeout: int = 1):- Scans a UDP port on the target IP.
- Returns a tuple containing the port, status (open/closed), and service.
scan_syn_port(ip: str, port: int, timeout: int = 1):- Performs a SYN scan on the target IP.
- Returns a tuple containing the port, status (open/closed), and service.
1async_scan_tcp_port(ip: str, port: int, timeout: int = 1, version_detection: bool = False, os_detection: bool = False):- Asynchronously scans a TCP port on the target IP.
- Optionally detects service version and OS.
- Returns a tuple containing the port, status (open/closed), and service.
-
Advanced Features
advanced_data_analysis(results: List[Dict[str, Any]]):- Performs advanced data analysis using machine learning (Random Forest).
- Analyzes scan results to identify suspicious patterns and predict potential attacks.
detect_suspicious_traffic(traffic_data: List[Dict[str, Any]]):- Detects suspicious traffic patterns based on packet size and other factors.
detect_anomalies(traffic_data: List[Dict[str, Any]]):- Detects anomalies in traffic data using Isolation Forest.
generate_security_recommendations(analysis: Dict[str, int]):- Generates security recommendations based on scan analysis.
predict_attacks(results: List[Dict[str, Any]]):- Predicts potential attacks using machine learning (Random Forest).
-
IoT and Vulnerability Assessment
identify_iot_devices(results: List[Dict[str, Any]]):- Identifies IoT devices based on open ports and services.
evaluate_iot_vulnerabilities(results: List[Dict[str, Any]]):- Evaluates vulnerabilities in IoT devices based on open ports and services.
-
Historical and Comparative Analysis
compare_with_previous_scan(current_results: List[Dict[str, Any]], previous_results_file: str):- Compares current scan results with previous scan results to identify changes.
generate_historical_report(scan_history_file: str):- Generates a historical report based on past scan results.
-
Website Vulnerability Scanning
scan_website(url: str):- Scans a website for common vulnerabilities such as SQL Injection, XSS, insecure code, SSL/TLS issues, and more.
- The script supports multiple output formats, including JSON, CSV, XML, HTML, and PDF.
- It can generate charts and maps based on scan results.
- The script can be configured to run scheduled scans at regular intervals.
- It supports encryption of scan results for secure storage and transmission.
- Use this script only for legal purposes and with proper authorization.
- Ensure you have permission from the target system owner before scanning.
- Using Tor may reduce scan speed but increases anonymity.
- If you would like to contribute to the development of this project, please submit a Pull Request or report new Issues.
- This project is licensed under the MIT License. For more information, see the LICENSE file.
For questions, feedback, or bug reports, contact the maintainer:
- Email: MrAmirRezaie70@gmail.com
- Telegram: @MrAmirRezaie
- GitHub: MrAmirRezaie
Enjoy using the Advanced Port Scanner! 🚀