Skip to content
Tutorials Center
My learning

Topics

Lesson 6 of 36 ยท Scanning Basics

Reading Nmap Output

Learn to read Nmap's report and save it with -oN, -oX, -oG and -oA, then parse normal and grepable output in Python to turn scans into usable data.

A scan is only useful if you can read the result, keep it, and feed it to other tools. Nmap prints a human-friendly report to the screen and can also save the same data in several file formats. This lesson explains every part of the normal report and the four output options, and then you will parse the output with Python.

All sample output below is invented and labelled. The Python editors parse the text you see; nothing is scanned.

Anatomy of a report

Here is a slightly bigger example, produced by a hypothetical scan with service detection:

TEXT
Starting Nmap 7.9x ( https://nmap.org ) at 2026-11-12 10:30 UTC
Nmap scan report for web01.example.net (192.0.2.10)
Host is up (0.0030s latency).
Not shown: 995 closed tcp ports (reset)
PORT     STATE    SERVICE  VERSION
22/tcp   open     ssh      OpenSSH 9.x (protocol 2.0)
80/tcp   open     http     nginx 1.2x.x
443/tcp  open     ssl/http nginx 1.2x.x
3306/tcp filtered mysql
8080/tcp open     http-proxy
Service Info: OS: Linux

Nmap done: 1 IP address (1 host up) scanned in 7.84 seconds

Example output (invented; version numbers are placeholders).

Part What it tells you
Nmap scan report for NAME (IP) Start of one host's results. The name is reverse DNS if it exists.
Host is up (latency) Host discovery worked; latency is the round-trip time.
Not shown: N state ports (reason) Summary of the most common uninteresting state
PORT STATE SERVICE [VERSION] The table; the number and protocol, the state, the service guess or detected software
Service Info Extra facts from version detection, such as the OS or device type
Nmap done Totals and elapsed time

When many ports share the same state, Nmap hides them behind "Not shown" so the interesting ones stand out. If more than 25 ports of a state are found, it collapses that state; with -v and --open you can control this.

The four output formats

You can print to the screen and write files at once. Pick one or several:

Option Format Best for
-oN file Normal: the same text as the screen Reading and archiving
-oX file XML: complete, structured Programs, importing into tools
-oG file Grepable: one line per host Quick grep/awk (deprecated, but widely used)
-oA basename All three at once: basename.nmap, .xml, .gnmap The recommended habit
Terminal
nmap -sS -oA scans/web01 192.0.2.10

This creates scans/web01.nmap, scans/web01.xml and scans/web01.gnmap. Using -oA from the start means you never wish you had saved the XML later. Add -oN - style filenames only if you need to send output to the terminal explicitly; a lone - means standard output.

Two related options: --append-output adds to an existing file instead of overwriting it, and --stylesheet links an XSLT file so an XML report opens in a browser as a formatted page. -oS ("script kiddie" output, l33t spelling) exists as a joke; ignore it.

Grepable format

Each host is one line, fields separated by tabs, ports separated by commas:

TEXT
# Nmap 7.9x scan initiated Thu Nov 12 10:30:00 2026 as: nmap -sS -oG - 192.0.2.10
Host: 192.0.2.10 (web01.example.net)	Status: Up
Host: 192.0.2.10 (web01.example.net)	Ports: 22/open/tcp//ssh///, 80/open/tcp//http///, 3306/filtered/tcp//mysql///	Ignored State: closed (997)

Each port is number/state/protocol/owner/service/rpc-info/version/ with empty slots for fields that do not apply. It is easy to grep "80/open" for a quick answer.

XML format

XML is the format to use for automation because it carries every detail unambiguously. A fragment looks like this:

XML
<host>
  <status state="up" reason="syn-ack"/>
  <address addr="192.0.2.10" addrtype="ipv4"/>
  <hostnames><hostname name="web01.example.net" type="PTR"/></hostnames>
  <ports>
    <port protocol="tcp" portid="22">
      <state state="open" reason="syn-ack"/>
      <service name="ssh"/>
    </port>
  </ports>
</host>

You will parse a piece like this in Reporting and Automation, later in the course.

A stand-in: parse the normal report

This parser reads a normal-format report and returns structured data, with a regular expression for each table row.

Python Parse normal output into a table

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.

Notice that the head regex handles both name (ip) and a bare ip line, which Nmap prints when no reverse DNS name exists.

A stand-in: parse grepable output

The grepable line is even easier to parse, because the separators are fixed: tabs between fields, commas between ports, slashes inside a port.

Python Parse a grepable line

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.

Choosing a format

  • Keep the XML (-oX) of every serious scan: it contains everything and survives tool changes.
  • Keep the normal text for reading.
  • Use grepable only for quick shell one-liners; the Nmap project marks it as obsolete and recommends XML for scripts.
  • Name files with the date and target (2026-11-12-web01) so scans can be compared later.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which single option writes normal, XML and grepable output at once?

    -oA basename writes basename.nmap, basename.xml and basename.gnmap.
  2. 2. Which format should automation scripts parse by preference?

    XML is complete and unambiguous; grepable and normal are for humans and quick pipelines.
  3. 3. What does the line Not shown: 995 closed tcp ports (reset) mean?

    Nmap collapses the most common boring state to keep the table short.
  4. 4. In grepable output, what separates the ports of one host?

    Ports are comma-separated on a single Ports: field; fields themselves are tab-separated.

Summary

  • A report has a host header, latency, a "Not shown" summary and a PORT/STATE/SERVICE table.
  • Use -oN, -oX, -oG or -oA to save results; -oA is the habit to adopt.
  • XML is best for programs; grepable is quick but obsolete; normal is for people.
  • Regular expressions and string splitting are enough to turn output into data.

Next: Port States Explained