M. Wolf
M. Wolf

Reputation: 67

Python, Output of Nmap NSE scripts (libnmap module)

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

Upvotes: 2

Views: 2152

Answers (1)

mohamed tehami
mohamed tehami

Reputation: 123

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']
       

Upvotes: 2

Related Questions