2

I'm trying to get the output of a Nmap NSE script to output properly to my terminal. I'm using the libnmap module, and have read a few examples as well as the documentation, so I'm not sure where I'm going wrong.

from libnmap.parser import NmapParser

p = NmapParser.parse_fromfile("test.xml")
for host in p.hosts:
    for service in host.services:
        for script_out in service.scripts_results:
            print "Output of {0}: {1}".format(script_out['id'], script_out['output']

When I ran the script above, nothing outputted. If I get the logic of the above script to work properly, then I can probably get it to work in my main script.

I ran this nmap scan in my terminal to test the script. nmap -sV --script dns-brute.nse -oX test.xml google.com

M. Wolf
  • 67
  • 7
  • What's the output if you do `for host in p.hosts: print host`? – André Laszlo Apr 05 '16 at 15:06
  • NmapHost: [216.58.216.110 (google.com ord30s22-in-f14.1e100.net) - is up] – M. Wolf Apr 05 '16 at 16:00
  • Oh, I was hoping to see some kind of dictionary structure. But maybe the `.services` and/or `.scripts_results` are empty for some reason? Maybe the parser and the xml doesn't map 1:1? One way to figure out is to run your code inside [IPython](http://ipython.org) and check what's inside the object returned by `parse_fromfile`, either by using `dir` or using tab completion. – André Laszlo Apr 05 '16 at 16:03

1 Answers1

2

I was stuck on the same problem, after reviewing the source code and the xml file, you'll notice that while the script scan the host running a script on the xml file there is the element Hostscript which make the difference between other script lunched (ex: ftp-anon )

well try out this, it should work

from libnmap.parser import NmapParser

p = NmapParser.parse_fromfile("test.xml")
for host in p.hosts:

  for script_out in host.scripts_results:
    print "Output of {0}: {1}".format(script_out['id'],script_out['output']
       
mohamed tehami
  • 113
  • 1
  • 11