-1

Situation:

I am using Nmap to do network scanning and would like to create a script that takes some Nmap output in XML and parses it and based on that prints the information I want.

Problem Description:

This parser should:

  • Be able to be to take a given input and produce an output

  • The input should be an XML File.

  • The output should be one of these 2 things:

    1. Be able to print text on the terminal
    2. Be able to output processed information to a text file, or an HTML one.

Conclusion:

I need to build a parser that has the above-mentioned functionality, how do I implement it? Or, if possible, is there any ready-built solution that has the required functionality?

Edit 1: I would like to use a bash script, and a bash script is the most preferred answer, but I am open to other languages also.

Jandroid
  • 111
  • 1
  • 11

1 Answers1

2

The first thing that comes to my mind for processing nmap results is Zenmap, but that's more of a GUI for nmap. You might want to check out nmap-parse, it's a commandline tool that seems to provide what you want; although I've never used it myself so I cannot vouch for it.

I should point out that if you are somewhat familiar with Python creating a custom script to parse nmap output is pretty simple. Here is example I created after looking through the documentation of Python xml module and the nmap XML output:

import xml.etree.ElementTree as ET
tree = ET.parse('output.xml')
root = tree.getroot()

for host in filter(lambda h: h.tag == 'host', root):
    status = host.find('status')
    address = host.find('address')
    print('Host', address.attrib['addr'], 'is', status.attrib['state'])
Matt
  • 699
  • 5
  • 15
  • Hi, thanks, but is there a way to implement this using bash scripting? – Jandroid Dec 13 '21 at 13:48
  • Also, this tool looks good, and I will post an edit or answer when I have tested it and it does the job. – Jandroid Dec 13 '21 at 13:52
  • Although technically possible, parsing xml within bash is kind of a controversial topic (see [this question](https://stackoverflow.com/questions/893585/how-to-parse-xml-in-bash)) I highly doubt it will leave you with a script as simple as the Python one. – Matt Dec 13 '21 at 13:56
  • Actually, that link had my solution, but also thanks a lot for the python alternative. I have marked this answer as accepted. – Jandroid Dec 13 '21 at 14:15