Mastering Nmap Output Formats: Syntax, Exporting, and Data Processing
Nmap output formats determine how scan results are captured, structured, and exported for analysis. Network Security Scanner (Nmap) provides five primary output flags: Normal (-oN), XML (-oX), Grepable (-oG), Script Kiddie (-oS), and All Formats (-oA), in addi...
Nmap output formats determine how scan results are captured, structured, and exported for analysis. Network Security Scanner (Nmap) provides five primary output flags: Normal (-oN), XML (-oX), Grepable (-oG), Script Kiddie (-oS), and All Formats (-oA), in addition to standard interactive screen output. Selecting the right format allows network engineers and security professionals to generate human-readable reports, integrate scan data into automated security pipelines, and ingest results into vulnerability management platforms.
Contents
Overview of Available Nmap Output Formats
When running a scan without specifying output directives, Nmap streams its results directly to the standard output (stdout) stream. This default interactive display provides real-time progress updates, status messages, and a clean summary of open ports, services, and OS detection results. However, interactive output is lost once the terminal session closes unless explicitly saved to a persistent file format.
Normal Output (-oN)
The Normal output format, requested via the -oN flag, writes scan results to a file in a layout nearly identical to the interactive standard output. It includes header information detailing the Nmap version, command-line arguments used, start time, host state summaries, port tables with service and version details, and script output execution summaries.
Normal output is engineered for human readability. Security analysts frequently use .nmap files for manual review, security audit documentation, and quick reference during penetration testing engagements. Because it retains plain-text formatting, it can be inspected using standard terminal pagers like less or basic text editors.
XML Output (-oX)
The XML output format, generated using -oX , is the standardized format for machine processing, automation, and platform integration. The resulting file adheres to the official Nmap Document Type Definition (DTD), hosted publicly by the project maintainers at Nmap DTD Source.
XML output captures every granular detail of the scan process, including:
- Exact packet timing and round-trip time (RTT) measurements for every probed host.
- Detailed TCP/IP stack fingerprinting data used for operating system classification.
- Complete Nmap Scripting Engine (NSE) structured output elements, key-value pairs, and raw tables.
- Detailed reason codes explaining why a specific port was marked as
open,closed, orfiltered.
Security Operations Center (SOC) teams and vulnerability management tools—such as Metasploit, DefectDojo, and Greenbone Vulnerability Management—rely on XML output for programmatic ingestion and automated asset tracking.
Grepable Output (-oG)
The Grepable output format, specified with -oG , structures scan data into single-line entries per host. This design allows command-line utilities such as grep, awk, sed, and cut to filter and extract target information without complex multiline parsing logic.
Each line in a .gnmap file contains key details separated by tabs and commas, including IP address, hostname, host status (Up or Down), open ports, service names, and protocol types. While Nmap developers consider Grepable output a legacy format due to its inability to capture complex Nmap Scripting Engine (NSE) objects or full OS fingerprinting data, it remains widely used for rapid command-line filtering during internal network assessments.
Script Kiddie Output (-oS)
The Script Kiddie output format, activated via -oS , is a humorous historical feature introduced in early Nmap releases. It formats the scan output into stylized "l33tspeak" capitalization and letter substitutions (such as replacing e with 3 or a with @).
While functional as a text file, Script Kiddie output serves no professional operational purpose in security engineering or enterprise auditing. It is generally avoided in production environments because it breaks machine parsers and reduces human readability.
Combined Output (-oA)
The Combined output option, specified using -oA , generates files in Normal (.nmap), XML (.xml), and Grepable (.gnmap) formats simultaneously under the designated base file name. For example, running nmap -sS -oA perimeter_scan 192.168.1.0/24 creates perimeter_scan.nmap, perimeter_scan.xml, and perimeter_scan.gnmap in the current working directory.
Using -oA is considered standard best practice for security assessments. It ensures that human-readable logs are instantly available for quick reference while structured XML files are preserved for long-term archiving and tool automation.
Comparative Analysis of Nmap Output Formats
Selecting the appropriate output format depends on whether the data will be read by an analyst, processed by terminal shell scripts, or ingested into enterprise vulnerability platforms. The table below outlines the operational attributes of each format.
| Output Flag | File Extension | Primary Audience | Structured Data Support | Human Readability | Best Use Case |
|---|---|---|---|---|---|
Interactive (stdout) |
None | Operator | Low | High | Real-time terminal monitoring during active scans |
Normal (-oN) |
.nmap |
Human Analyst | Medium | High | Manual security reporting, audit evidence, text notes |
XML (-oX) |
.xml |
Machine / Software | Complete | Low | Database ingestion, SIEM integration, automated reporting |
Grepable (-oG) |
.gnmap |
Shell Scripts | Low | Medium | Rapid text extraction via command-line utilities (grep/awk) |
Script Kiddie (-oS) |
.l33t |
Novelty | Low | Low | Demonstrations, entertainment, historical interest |
All Formats (-oA) |
.nmap, .xml, .gnmap |
Mixed Workflows | Complete | High | Enterprise baseline scanning, comprehensive engagements |
Technical Directive Syntax and Output Controls
Nmap provides flags to control where output is sent, how existing files are updated, and how stylesheets are linked for browser viewing.
Redirecting Output to Standard Output
By default, supplying a file path to -oN or -oX writes data to disk. However, passing a hyphen (-) as the file path redirects that specific output format directly to standard output. This technique allows operators to pipe structured XML directly into downstream processing tools or remote log collectors.
For example, running nmap -sV -oX - target.local | python3 parse_xml.py streams the XML data directly to an external Python parsing script without leaving intermediate artifacts on the local filesystem.
Appending vs. Overwriting Output Files
By default, Nmap overwrites any pre-existing file matching the path provided to an output argument. To append new scan findings to existing output files without destroying historical entries, use the --append-output flag alongside your export arguments.
For example, running nmap -sT -p 80,443 --append-output -oN daily_audit.nmap 10.0.0.0/8 appends the findings of the subnet sweep to daily_audit.nmap if it already exists, or creates it if it does not.
Managing XML Stylesheets for Web Display
Nmap includes an XML Stylesheet Language (XSL) reference inside generated XML files. This allows web browsers to automatically transform the raw XML data into a structured, styled HTML page when opened directly.
- Default Stylesheet Reference: By default, Nmap embeds an XML processing instruction referencing
nmap.xslin the installation directory. - Web-Hosted Stylesheet (
--webxml): Adding--webxmldirects the browser to load the official XSL stylesheet hosted by Nmap.org at Nmap Web XSL. This permits rendering portable HTML views on machines that lack a local Nmap installation. - Custom Stylesheet (
--stylesheet): Specifies an enterprise-specific or localized XSL transform stylesheet path. - Suppressing Stylesheets (
--no-stylesheet): Omits the XSL rendering directive entirely, reducing file overhead when XML files are strictly used for database parsing.
Fine-Tuning Output Detail: Verbosity and Debugging Flags
The volume of detail captured in both terminal streams and Normal output logs depends on verbosity and debugging levels. Adjusting these flags exposes lower-level network interactions, packet states, and execution timings.
Nmap Verbosity Levels
| Level | Description |
|---|---|
| Level 0 | Default standard output (displays open ports/summary) |
| Level 1 | -v (Shows scan progress, open ports as found) |
| Level 2 | -vv (Shows open/closed ports, timing updates, reason) |
Nmap Debugging Levels
| Level | Description |
|---|---|
| Level 1 | -d (Displays detailed internal execution state) |
| Level 2+ | -dd (Includes packet headers, raw probe details) |
Adjusting Verbosity (-v and -vv)
Adding -v increases verbosity, causing Nmap to print open ports immediately upon discovery rather than waiting for the entire scan phase to finish. It also outputs estimated completion times, firewall detection warnings, and additional details regarding operating system detection.
Using double verbosity (-vv) expands progress output further, detailing closed ports, connection resets, and probe retry attempts.
Enabling Debugging Modes (-d and -dd)
When troubleshooting network connectivity issues, false positives, or custom Nmap Scripting Engine scripts, debugging flags provide low-level protocol insights.
- Level 1 Debugging (
-d): Prints raw interface configurations, routing table calculations, target state changes, and internal script execution steps. - Level 2+ Debugging (
-dd): Exposes raw packet headers, payload fragments, response flags, and exact timing algorithms used by Nmap's parallel scan engine.
Exposing Port Decision Reasons (--reason)
The --reason flag appends an additional column or field to port tables explaining why a port was classified into a given state. For instance, an open port might display reason: syn-ack, indicating a TCP SYN-ACK packet was received in response to a probe. A filtered port might display reason: host-unreachable or reason: no-response, clarifying whether an ICMP administrative prohibition or a firewall drop prevented communication.
Parsing Nmap XML and Grepable Data in Automated Pipelines
Security operational automation relies on extracting actionable host and port data from raw scan logs. Below are standard methods for processing Nmap outputs using standard system utilities and scripting platforms.
Converting XML to HTML Reports with XSLT
Network auditors can transform Nmap XML output into a standalone HTML report using xsltproc (an open-source XSLT command-line processor maintained via GNOME libxslt documentation).
To generate an HTML report, execute: xsltproc scan_results.xml -o scan_report.html
This command applies the XSL stylesheet embedded in scan_results.xml to generate a self-contained, browser-ready HTML file suitable for presentation to executive stakeholders or network administrators.
Extracting Target IPs from Grepable Output Using Unix Shells
Grepable output (.gnmap) is optimized for command-line string matching. For example, to extract a clean list of all live IP addresses with port 22 (SSH) open from a large network sweep, use the following shell pipeline:
grep "/open/tcp//ssh/" scan_results.gnmap | awk '{print $2}' > live_ssh_hosts.txt
In this command string:
grepfilters lines matching open SSH ports across the scanned subnet.awk '{print $2}'isolates the second field of the output line, which corresponds to the host IP address.- The resulting IP list is saved to
live_ssh_hosts.txtfor secondary testing or configuration management.
Programmatic Processing via Python
Python scripts can parse structured Nmap XML files using native libraries like xml.etree.ElementTree or dedicated third-party packages such as python-nmap.
import xml.etree.ElementTree as ET tree = ET.parse('scan_results.xml') root = tree.getroot() for host in root.findall('host'): ip = host.find('address').attrib['addr'] status = host.find('status').attrib['state'] if status == 'up': for port in host.findall('.//port'): port_id = port.attrib['portid'] state = port.find('state').attrib['state'] service = port.find('service').attrib['name'] if port.find('service') is not None else 'unknown' print(f"Host: {ip} | Port: {port_id} | State: {state} | Service: {service}")
This snippet parses the XML tree, extracts live host IP addresses, iterates over scanned ports, and outputs formatted service details ready for database storage or alerting.
Session Recovery and Output Management in Enterprise Environments
Large enterprise sweeps across class-B or class-A IP blocks can run for hours or days. Maintaining output file integrity and enabling scan session resumption are critical for enterprise security operations.
Resuming Interrupted Scans (--resume)
If a long-running scan crashes or is cancelled due to network disruptions, Nmap can resume execution from the exact point of interruption provided Normal (-oN) or Grepable (-oG) logging was enabled.
To resume an interrupted scan session, run: nmap --resume cancelled_scan.nmap
Nmap reads the tail end of cancelled_scan.nmap or cancelled_scan.gnmap to determine which target IP addresses were fully completed, skips those targets, and continues scanning the remaining IP addresses in the original target list using the exact flags specified in the initial run.
Storage Optimization and Retention
When scanning thousands of hosts continuously, XML files can grow rapidly due to full script execution traces and packet timing metrics. Security teams should implement structured log archiving strategies:
- Compress completed XML and Normal logs using
gziporzstdpost-scan to reduce storage footprints by up to 90%. - Avoid writing raw packet trace files (
--packet-trace) to disk during routine production scans, reserving packet-level logging strictly for diagnostic troubleshooting on specific target subsets. - Standardize on the
-oAdirective combined with consistent naming conventions (such as incorporating ISO date stamps, likenmap -oA scan_prod_2026-03-30 10.0.0.0/16) to organize security baseline repositories.
Frequently Asked Questions About Nmap Output Formats
How do I save Nmap results in all major formats simultaneously?
Use the -oA command option. This flag outputs scan results into Normal (.nmap), XML (.xml), and Grepable (.gnmap) files at the same time using the specified base filename, ensuring both human-readable and machine-parsable formats are captured in a single scan.
Which Nmap output format is best for automation and scripting?
The XML output format (-oX) is the industry standard for software integrations, security scripts, and automated database ingestion. It provides complete, structured access to host information, port states, service versions, timing statistics, and script results following an official Document Type Definition (DTD).
How can I convert Nmap XML output into an HTML web report?
You can transform Nmap XML files into styled HTML documents using the command-line utility xsltproc. Running xsltproc input.xml -o output.html parses the XML according to the embedded stylesheet instructions, generating a self-contained web report that can be viewed in any modern browser.
How do I resume an interrupted Nmap scan using previous output files?
Pass the --resume directive along with the path to an existing Normal (.nmap) or Grepable (.gnmap) output file from the canceled run. Nmap reads the completed hosts from the log and resumes probing the remaining targets without repeating work.
What is the difference between interactive stdout and Normal (-oN) output?
Interactive standard output (stdout) streams live results directly to the terminal screen during scan execution. Normal output (-oN) writes those same results directly to a persistent plain-text file on disk, preserving header details, host summaries, and service tables for future audit review.
Standardizing Output Logging in Security Operations
To maximize the value of Nmap scan data across enterprise environments, security engineering teams should adopt standardized logging practices. Establishing operational rules around file generation ensures audit compliance, simplifies automated parsing, and prevents unexpected operational failures.
First, default to using -oA for scheduled network inventory checks and vulnerability assessments. Storing both XML and plain-text files ensures that security automation pipelines have access to structured data while operational staff can immediately review plain-text output without requiring specialized parsing tools.
Second, incorporate date and scope indicators into base file names. Utilizing standardized naming conventions—such as nmap -oA /var/log/scans/internal_10.10.0.0_2026-03-30—prevents accidental file overwriting, simplifies historical trend analysis, and ensures clear chain-of-custody documentation during security incident investigations.
Finally, ensure output directories are monitored for available disk capacity. When running large-scale port sweeps across vast IP ranges with verbosity or script output enabled, XML files can expand to hundreds of megabytes. Setting up log rotation schedules, compressing historical logs, and directing scan outputs to dedicated storage volumes prevents enterprise scanning jobs from running out of disk space mid-assessment.
EDITORIAL CATEGORY METADATA: