nmaparse.py is a Python script that parses Nmap’s “grepable” output (.gnmap files) and then inserts them into a MySQL database. If a host has multiple ports open, it expands the results into multiple lines — one port per line into the following fields:

  • Host
  • Port
  • OS
  • Seq Index
  • IPID Seq
  • Scan date
  • Scan flags

The script then splits up the port information into the following subfields:

  • Port
  • Protocol
  • State
  • Service
  • Version

Together, the aforementioned fields make up each result. This allows you to load the results up into a database and perform all sorts of analysis, network device monitoring, etc. The script requires the Python MySQLdb module, and has been tested using Python 2.5.2. It uses this database schema (nmapdb.sql), though nothing stops you from using your own.

To use the script, it’s as simple as:

$ ./nmaparse.py results.gnmap
Number of rows inserted: 35 results
$ ./nmaparse.py *.gnmap
Number of rows inserted: 1520 results

You can also download nmaparse.py directly.