Nmap Output Format Options: A Complete Guide to Exporting Scan Data
Nmap provides five primary output formats to capture network scan results: Normal (-oN), XML (-oX), Grepable (-oG), Script Kiddie (-oS), and All Formats (-oA). Choosing the correct output option allows security professionals to balance...
Nmap provides five primary output formats to capture network scan results: Normal (-oN), XML (-oX), Grepable (-oG), Script Kiddie (-oS), and All Formats (-oA). Choosing the correct output option allows security professionals to balance human readability with automated parsing for reporting, security auditing, and enterprise tool integration.
Contents
Understanding Nmap Output Formats
Network mappers and security auditors require flexible ways to capture scan findings. By default, Nmap prints its scan results directly to standard output (stdout) in an interactive, human-readable format. However, relying solely on terminal output makes long-term tracking, forensic analysis, and automated ingestion into vulnerability management platforms difficult.
Nmap addresses this by offering specialized flags that redirect or convert raw scan data into distinct file structures. Whether your workflow demands human-readable text logs, machine-parsable XML trees, line-delimited files for Unix command-line utilities, or automated multi-format exports, Nmap provides dedicated command-line arguments to suit each scenario.
Primary Nmap Output Options
1. Normal Output (-oN)
The Normal output format redirects the default interactive terminal display into a designated file. The syntax uses the flag -oN followed by the target filename, such as nmap -oN scan_results.txt 192.168.1.1.
This format preserves the familiar structure seen on screen during an interactive session. It includes header details such as the Nmap version, scan invocation parameters, starting timestamp, host status, open ports, service versions, OS detection estimations, and closing summary metrics.
Normal output is best suited for quick manual reviews, executive notes, or single-host technical audits where human readability is the primary requirement. While plain text files can be read with standard text editors, parsing them automatically using scripts can be complex because Nmap modifies line spacing and layouts depending on active Nmap Scripting Engine (NSE) scripts or verbosity levels.
2. XML Output (-oX)
The XML output format, invoked with -oX (for example, nmap -oX scan_results.xml 192.168.1.1), is the most robust and complete output format supported by Nmap. It structures all discovered host data, port states, protocol details, service banners, operating system guesses, and NSE script output into a well-formed Document Type Definition (DTD) schema.
Security teams rely heavily on XML output for downstream technical workflows. Mainstream vulnerability scanners, asset management tools, and penetration testing frameworks—including Metasploit, Zenmap, and Faraday—natively ingest Nmap XML files.
Nmap also includes XML Document Type Definition rules and an XSL stylesheet (nmap.xsl) that can convert XML files into interactive HTML pages when opened in modern web browsers. You can specify a local or custom stylesheet using --stylesheet or instruct Nmap to use the official hosted stylesheet using --webxml.
3. Grepable Output (-oG)
The Grepable format, specified using -oG (such as nmap -oG scan_results.gnmap 192.168.1.0/24), formats all information regarding a single host onto a single line of text. This design makes it simple to search, filter, and manipulate results using classic Unix text-processing utilities like grep, awk, cut, and sed.
A typical Grepable output line begins with the host IP address and hostname, followed by tab-delimited key-value blocks detailing host status, open ports, protocol numbers, state, service names, and version attributes.
While highly popular for quick command-line filtering, official Nmap documentation notes that the Grepable format is legacy and cannot represent complex data structures generated by modern NSE scripts, IPv6 traceroutes, or advanced service detection. For complex automation pipelines, XML remains the recommended choice, though Grepable output remains popular for rapid command-line querying across large subnets.
4. All Formats Export (-oA)
During extensive security assessments, operators frequently need both human-readable documentation and structured machine-parsable files. Rather than running multiple individual output flags, Nmap provides the combined export argument -oA followed by a base filename prefix.
For instance, executing nmap -oA target_network 192.168.1.0/24 simultaneously generates three separate files:
target_network.nmap(Normal output format)target_network.xml(XML output format)target_network.gnmap(Grepable output format)
Using -oA ensures all formats share exact data captured during the exact same scan window, preventing discrepancies across files.
5. Script Kiddie Output (-oS)
The Script Kiddie format (-oS) is an alternative output mode that converts terminal text into stylized "l33t speak" text (replacing letters with visually similar numbers and characters). For example, nmap -oS scan.txt 192.168.1.1 formats standard output with character substitutions across header lines and findings.
This mode exists primarily as an internal joke within the tool's history. It serves no practical analytical or enterprise function and should not be used in formal reports or production monitoring pipelines.
Technical Comparison of Nmap Output Formats
The table below outlines the core attributes, default file extensions, primary use cases, and parsing capabilities across all supported Nmap output options.
| Output Flag | Format Name | Default Extension | Machine Parsable | Human Readable | Primary Use Case |
|---|---|---|---|---|---|
-oN |
Normal | .nmap |
Low | High | Manual review, fast notes, standard log capture. |
-oX |
XML | .xml |
High (Structured DTD) | Moderate (High via XSLT) | Integration with scanners, web visualization, programmatic scripts. |
-oG |
Grepable | .gnmap |
Moderate (Line-based) | Moderate | Rapid CLI extraction using grep, awk, and sed. |
-oA |
All Formats | .nmap, .xml, .gnmap |
High | High | Comprehensive record-keeping for pentests and vulnerability management. |
-oS |
Script Kiddie | .sk |
None | Low | Historical curiosity / aesthetic styling. |
Output Customization and Verbosity Controls
The specific content saved inside any output file depends on Nmap’s verbosity, debugging settings, and execution modifiers. By default, Nmap omits closed or filtered ports from detailed output lists to maintain clean logs.
Adjusting Verbosity and Debugging
- Verbosity Levels (
-v,-vv): Adding-vincreases the amount of information printed and logged during execution. It reveals open ports instantly as they are discovered, displays scan timing updates, and shows additional host detail. Using double verbosity (-vv) reveals finer details like packet timing adjustments and port states. - Debugging Flags (
-d,-dd): Intended for troubleshooting failed scans or script execution errors, debugging flags capture low-level system events, socket calls, and raw response details within the output logs. - Reason Flag (
--reason): Adding--reasoninstructs Nmap to include explicit explanation codes in both screen and file output showing why a port was determined to be open, closed, or filtered (such assyn-ack,conn-refused, orno-response).
File Handling: Appending vs. Overwriting
By default, specifying an output file flag will overwrite an existing file with the same name without warning. To preserve existing data and append new scan findings to an established log file, use the --append-output flag:
nmap -sV --append-output -oN daily_audit.txt 192.168.1.0/24
This prevents accidental data loss during scheduled cron jobs or multi-stage penetration testing engagements.
Redirecting Output to Standard Streams
When building custom shell pipelines, operators sometimes require XML or Grepable output directed straight to stdout without saving a persistent file to the disk. Passing a hyphen (-) as the filename directs Nmap to stream the output to standard output:
nmap -sV -oX - 192.168.1.50
This approach lets you stream Nmap data directly into third-party parsers, remote socket endpoints, or encryption utilities without writing unencrypted scan data to storage drives.
Parsing and Automating Nmap Output Data
Leveraging Nmap data within enterprise workflows requires effective techniques for processing XML and Grepable files.
Rendering XML Files into HTML Browsers
Nmap XML files contain standard processing instructions that reference an XSL stylesheet. To render XML files directly as interactive HTML tables in modern browsers, apply the --webxml option during execution:
nmap -A -oX report.xml --webxml 192.168.1.1
When opened in a web browser, report.xml fetches the official stylesheet hosted on Nmap's documentation site and presents collapsible menus, search bars, and formatted port listings. Alternatively, offline environments can transform XML files locally using command-line processors like xsltproc:
xsltproc report.xml -o report.html
Programmatic XML Parsing with Python
Python provides libraries such as xml.etree.ElementTree and third-party modules like python-nmap to parse structured XML files programmatically.
Using native XML parsing allows security engineers to extract open ports, running service details, and script outputs with precision:
import xml.etree.ElementTree as ETtree = ET.parse('scan_results.xml')root = tree.getroot()for host in root.findall('host'): ip = host.find('address').attrib['addr'] print(f"Host: {ip}")
This structured approach avoids the fragility of regex matching against plain text files, enabling reliable security monitoring and database ingestion.
Quick Shell One-Liners with Grepable Format
While XML is ideal for script development, the Grepable format shines during live terminal tasks. For instance, to quickly extract all live IP addresses with port 80 open from a .gnmap file, use grep and awk:
grep "/open/tcp//http/" scan_results.gnmap | awk '{print $2}'
This command filters lines listing open HTTP services and prints only the second column (the IP address), providing a clean host list ready for further assessment tools.
Common Pitfalls and Best Practices
Avoiding Destructive File Overwrites
Running sequential Nmap commands using identical -oN or -oX filenames without --append-output will instantly overwrite previous scan results. When performing long-term assessment engagements, establish strict file-naming conventions incorporating timestamps or unique target identifiers:
nmap -sV -oA scan_192-168-1-1_$(date +%Y%m%d_%H%M%S) 192.168.1.1
Addressing Memory Constraints on Large Scans
Scanning massive IP ranges (such as /16 or /8 networks) with aggressive script scanning can generate XML files hundreds of megabytes in size. Processing massive XML files in memory using standard DOM parsers can cause high RAM utilization or process timeouts.
To manage large dataset sizes effectively:
- Segment large target IP ranges into smaller subnet chunks (such as
/24blocks). - Process XML streams iteratively using event-based parsers (like Python's
iterparse) rather than loading entire DOM trees into system memory. - Use file compression tools (
gzip) to reduce long-term storage requirements for historic log files.
Frequently Asked Questions
What is the best Nmap output format for automation?
XML (-oX) is the industry standard for automation. It uses a structured DTD schema that reliably represents complex information, including multi-port states, OS fingerprint probabilities, and detailed script execution outputs. Most security tools natively support importing Nmap XML output.
How do I save Nmap scan results in all formats simultaneously?
Use the -oA flag. For example, running nmap -oA audit_results 10.0.0.1 will simultaneously create audit_results.nmap (Normal text), audit_results.xml (XML format), and audit_results.gnmap (Grepable format) in your current directory.
How can I view an Nmap XML output file in a regular web browser?
Include the --webxml option during your scan execution (e.g., nmap -oX output.xml --webxml target). This attaches a stylesheet header that modern web browsers use to render the raw XML data into a readable, interactive HTML interface. Alternatively, convert the file offline using xsltproc output.xml -o output.html.
Can I append new scan findings to an existing Nmap log file?
Yes. Include the --append-output flag alongside your output file specification. For example, nmap --append-output -oN ongoing_log.txt 192.168.1.1 adds new scan data to the bottom of ongoing_log.txt without overwriting existing data.
Is the Grepable output format deprecated?
While Grepable format (-oG) remains fully functional and widely used for rapid command-line filtering, Nmap developers label it legacy. It cannot capture modern advanced features like complex multi-line script output or advanced IPv6 traceroute data. XML output (-oX) is recommended for complete, forward-compatible data parsing.
Recommended Next Steps
When setting up automated scanning schedules or manual penetration testing workflows:
- Standardize on the combined export flag (
-oA) for interactive terminal testing to ensure you capture both human-readable notes and structured technical output. - Store scan data in designated log directories using clear target-and-timestamp naming patterns to prevent unintended file overwrites.
- Integrate XML-based parsing scripts into your vulnerability management workflows to streamline host discovery and service inventory tracking.