Overview
The Scanner module (modules/scanner.py) provides comprehensive network reconnaissance capabilities using Nmap. It handles TCP/UDP port scanning, operating system fingerprinting, service detection, and version enumeration.
Scanner Class
TheScanner class is defined at scanner.py:13 and serves as the main interface for network scanning operations.
Initialization
scanner.py:14-24
Target IP address or domain name to scan
Key Methods
validate_target()
Validates that the target IP or domain is reachable before scanning.scanner.py:26-35
detect_os()
Detects the target’s operating system using Nmap’s OS fingerprinting or TTL analysis.scanner.py:37-79
OS detection requires root/sudo privileges for Nmap’s advanced fingerprinting features.
- Nmap OS Fingerprinting (
-Oflag): Most accurate, requires sudo - TTL Analysis (fallback): Less accurate but works without elevated privileges
scan_all_ports()
Performs comprehensive TCP and UDP port scanning with service version detection.scanner.py:81-140
Phase 1: TCP Scanning
Scans top 1000 TCP ports with service version detection using
-sS -sV -T4 -Pn --top-ports 1000enumerate_services()
Extracts detailed service information from discovered open ports.scanner.py:142-160
run_full_scan()
Orchestrates the complete scanning workflow.scanner.py:180-195
Usage Example
Nmap Arguments
The Scanner module uses these Nmap arguments:| Argument | Purpose |
|---|---|
-sS | TCP SYN scan (stealth) |
-sV | Service version detection |
-sU | UDP scan |
-O | OS detection |
-Pn | Skip ping (assume host is up) |
-T4 | Timing template (aggressive) |
--top-ports N | Scan N most common ports |
Output Format
Performance
- Top 1000 ports: ~30-60 seconds
- Top 20 UDP ports: ~10-20 seconds
- Full scan (all 65535 ports): 5-15 minutes
Error Handling
The Scanner module handles these common errors:Target Unreachable
Target Unreachable
Returns
None if target cannot be resolved or reached. Check network connectivity and DNS resolution.Permission Denied
Permission Denied
Nmap requires sudo for SYN scans (
-sS) and OS detection (-O). Run with sudo python3 main.py -t <target>.Scan Timeout
Scan Timeout
Increase timeout in config.json or reduce number of ports scanned.
Related Documentation
CLI Options
Command-line flags for scanner configuration
Configuration
Scanner settings in config.json
Troubleshooting
Solving permission and Nmap issues
Basic Scan Guide
Step-by-step scanning tutorial