Skip to content
Tutorials Center
My learning

Topics

Lesson 30 of 36 ยท Reporting and Automation

Output Formats: Normal, Grepable, XML and More

Learn every Nmap output format, when to use -oN, -oX, -oG and -oA, how to append, resume and compare, and how to read each format with small Python programs.

A scan result that only scrolls past on your screen is easy to lose. Nmap can write results to files in several formats, and choosing the right one decides how easily you can read, compare, search and automate them later. In this lesson you learn all the formats, their strengths and when to save more than one.

All sample output is illustrative and uses documentation addresses. Commands are shown read-only because Nmap cannot run on this site; the Python stand-ins read pasted text.

The formats at a glance

Option Format Best for
-oN file Normal: what you see on screen Reading, tickets, sharing
-oX file XML: structured and complete Programs, databases, reports
-oG file Grepable: one host per line Quick grep/awk (deprecated, but common)
-oS file "s <rIpt kIddi3": silly text
-oA basename All three (normal, XML, grepable) The habit to have
-oJ file JSON (newer Nmap versions only) Programs, if your version supports it

Use - instead of a file name to write to standard output (-oX -). Always prefer -oA: it creates basename.nmap, basename.xml and basename.gnmap in one run, so you never regret the format you did not save.

Terminal
# Example commands (read-only)
nmap -sV -oA scans/office-2026-11-12 192.0.2.0/25
nmap -oX - -p 80 192.0.2.10 | xmllint --format -
nmap --append-output -oN all-scans.txt 192.0.2.20
nmap --resume scans/office-2026-11-12.gnmap   # continue an interrupted scan

--append-output adds to an existing file instead of replacing it, and --resume restarts an interrupted scan from a normal or grepable file.

Normal output

Exactly what the terminal shows, minus runtime notices:

TEXT
# Nmap 7.98 scan initiated Thu Nov 12 10:00:00 2026 as: nmap -sV -oA office 192.0.2.10
Nmap scan report for web01.example.test (192.0.2.10)
Host is up (0.0004s latency).
Not shown: 998 closed tcp ports (reset)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 9.6p1 Ubuntu 3ubuntu13 (Ubuntu Linux; protocol 2.0)
80/tcp open  http    nginx 1.24.0 (Ubuntu)

Service detection performed.
# Nmap done at Thu Nov 12 10:00:08 2026 -- 1 IP address (1 host up) scanned in 7.91 seconds

The first comment line records the exact command, which is valuable when you look at the file months later.

Grepable output

One host per line, fields separated by tabs. It is easy to filter, but Nmap's documentation recommends XML for anything that matters, because the grepable format is limited and no longer extended.

TEXT
# Nmap 7.98 scan initiated ... as: nmap -oG - 192.0.2.10
Host: 192.0.2.10 (web01.example.test)	Status: Up
Host: 192.0.2.10 (web01.example.test)	Ports: 22/open/tcp//ssh//OpenSSH 9.6p1/, 80/open/tcp//http//nginx 1.24.0/	Ignored State: closed (998)

Port entries look like port/state/protocol/owner/service/rpc/version/. The quick one-liner for "which hosts have port 22 open" is grep "22/open" file.gnmap.

Python Read grepable output with Python

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

XML output

XML contains everything Nmap knows: the command, timing, every host and port, service details, script output, OS matches and traceroute. Programs read it reliably, and it is the base for reports and for diffing scans. A trimmed example:

XML
<nmaprun scanner="nmap" args="nmap -sV -oX - 192.0.2.10" start="1794477600">
  <host>
    <status state="up"/>
    <address addr="192.0.2.10" addrtype="ipv4"/>
    <hostnames><hostname name="web01.example.test" type="PTR"/></hostnames>
    <ports>
      <port protocol="tcp" portid="22">
        <state state="open" reason="syn-ack"/>
        <service name="ssh" product="OpenSSH" version="9.6p1"/>
      </port>
    </ports>
  </host>
  <runstats><finished elapsed="7.91"/><hosts up="1" down="0" total="1"/></runstats>
</nmaprun>

You can turn XML into a readable HTML report with an XSLT stylesheet: nmap -oX scan.xml --stylesheet nmap.xsl ... embeds a reference, and xsltproc scan.xml -o report.html makes the page. The next lesson, Parsing XML Output, reads XML with Python.

Verbosity, reasons and extra detail in files

  • -v and -vv add lines like open ports found during the scan.
  • --reason adds a "reason" for each state (syn-ack, reset, no-response), which makes files self-explaining.
  • --open shows only open (or possibly open) ports, which keeps files short for inventories.
  • --packet-trace logs every packet sent and received (large; for learning and debugging).
  • --stylesheet and --webxml set the XSLT used for HTML rendering.

Naming and organising files

Good file naming turns scan results into an archive:

TEXT
scans/
  2026-11-12_office_tcp-top1000.nmap
  2026-11-12_office_tcp-top1000.xml
  2026-11-12_office_tcp-top1000.gnmap

Include the date, the target name and the scan type. Keep the XML as the master copy. Store scans where only the security team can read them: they list every open port.

Python Generate consistent file names

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Which format when?

Task Format
Read results yourself Normal
Parse with a program XML (or JSON)
Quick one-off search Grepable
Compare today with last week XML with ndiff
Archive everything -oA

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which option writes normal, XML and grepable output in one run?

    -oA basename creates basename.nmap, basename.xml and basename.gnmap.
  2. 2. Which format is the best choice for programs and long-term archives?

    XML is complete and structured, so tools parse it reliably. The grepable format is limited and no longer extended.
  3. 3. What does --append-output do?

    By default Nmap overwrites an output file; --append-output adds to it.
  4. 4. Why is the first comment line of a normal-output file valuable?

    It tells you months later which options produced the results, which helps reproducing or interpreting the scan.
  5. 5. In grepable output, what is the field layout of a port entry?

    Entries are slash-separated: port, state, protocol, owner, service, RPC info and version, then a trailing slash.

Summary

  • Use -oA basename so you always have normal, XML and grepable files.
  • XML is the master format for automation; normal output is for people; grepable is for quick filters.
  • Record the date, target and scan type in file names, and protect the files.
  • --reason, --open and -v make saved results clearer and smaller.

Next: Parsing XML Output