Class Definition
Constructor
__init__(target_ip)
Initializes the NmapScanner with a target IP address.
The IP address of the target host to scan
target_ip(str): Target IP addressoutput_dir(Path): Directory for storing scan results ({Config.OUTPUT_BASE}/nmap)
Methods
full_scan()
Performs a comprehensive Nmap scan including service detection and OS fingerprinting.
- Ports: 1-1000 (top 1000 ports)
- Arguments:
-sV -sC -O --top-ports 1000-sV: Service version detection-sC: Default script scanning-O: OS detection
A Host object containing:
ip: Target IP addressos_detection: Detected OS with accuracy percentageports_open: Dictionary of open ports with service information
discover_network(network)
Static method to auto-discover active hosts in a network range.
Network range in CIDR notation (e.g., “192.168.1.0/24”)
- Uses
nmap -sn(ping scan) for host discovery - Filters out gateway (.1) and network (.0) addresses
- Timeout: 30 seconds
List of discovered IP addresses in the network
[Config.DEFAULT_TARGET] as fallback.
Implementation Details
OS Detection Logic
-
Primary: Uses
osmatchfield from Nmap results -
Fallback: Uses
osclassif osmatch unavailable
Service Detection
Extracts detailed service information for each open port:Dependencies
nmap: Python library for Nmap integrationpathlib.Path: File system operationssubprocess: Network discovery executionconfig.Config: Configuration settingsmodels.host.Host: Host data modelrich.print: Formatted console output