1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-07 21:21:31 +00:00

Rewrote some code in zenmap/zenmapCore/NmapParser.py to speed up opening of scans. Large scans open in seconds instead of hours now.

This commit is contained in:
jay
2014-06-09 06:29:20 +00:00
parent 8c82e5e3fe
commit 28ab4a621d

View File

@@ -476,7 +476,7 @@ class ParserBasics(object):
} }
self.ops = NmapOptions() self.ops = NmapOptions()
self._nmap_output = None self._nmap_output = StringIO.StringIO()
def set_xml_is_temp(self, xml_is_temp): def set_xml_is_temp(self, xml_is_temp):
# This flag is False if a user has specified his own -oX option - in # This flag is False if a user has specified his own -oX option - in
@@ -498,10 +498,16 @@ class ParserBasics(object):
self.ops.target_specs = targets self.ops.target_specs = targets
def get_nmap_output(self): def get_nmap_output(self):
return self._nmap_output return self._nmap_output.getvalue()
def set_nmap_output(self, nmap_output): def set_nmap_output(self, nmap_output):
self._nmap_output = nmap_output self._nmap_output.close()
del self._nmap_output
self._nmap_output = StringIO.StringIO(nmap_output)
def del_nmap_output(self):
self._nmap_output.close()
del _nmap_output
def get_debugging_level(self): def get_debugging_level(self):
return self.nmap.get('debugging', '') return self.nmap.get('debugging', '')
@@ -732,7 +738,7 @@ in epoch format!")
return ports return ports
profile_name = property(get_profile_name, set_profile_name) profile_name = property(get_profile_name, set_profile_name)
nmap_output = property(get_nmap_output, set_nmap_output) nmap_output = property(get_nmap_output, set_nmap_output, del_nmap_output)
debugging_level = property(get_debugging_level, set_debugging_level) debugging_level = property(get_debugging_level, set_debugging_level)
verbose_level = property(get_verbose_level, set_verbose_level) verbose_level = property(get_verbose_level, set_verbose_level)
scaninfo = property(get_scaninfo, set_scaninfo) scaninfo = property(get_scaninfo, set_scaninfo)
@@ -808,8 +814,8 @@ class NmapParserSAX(ParserBasics, ContentHandler):
def _parse_nmaprun(self, attrs): def _parse_nmaprun(self, attrs):
run_tag = "nmaprun" run_tag = "nmaprun"
if self._nmap_output is None and "nmap_output" in attrs: if self.nmap_output == "" and "nmap_output" in attrs:
self._nmap_output = attrs["nmap_output"] self.nmap_output = attrs["nmap_output"]
self.nmap[run_tag]["profile_name"] = attrs.get("profile_name", "") self.nmap[run_tag]["profile_name"] = attrs.get("profile_name", "")
self.nmap[run_tag]["start"] = attrs.get("start", "") self.nmap[run_tag]["start"] = attrs.get("start", "")
self.nmap[run_tag]["args"] = attrs.get("args", "") self.nmap[run_tag]["args"] = attrs.get("args", "")
@@ -1057,12 +1063,12 @@ class NmapParserSAX(ParserBasics, ContentHandler):
def characters(self, content): def characters(self, content):
if self.in_interactive_output: if self.in_interactive_output:
self.nmap_output += content self._nmap_output.write(content)
def write_text(self, f): def write_text(self, f):
"""Write the Nmap text output of this object to the file-like object """Write the Nmap text output of this object to the file-like object
f.""" f."""
if self._nmap_output is None: if self.nmap_output == "":
return return
f.write(self.nmap_output) f.write(self.nmap_output)
@@ -1100,7 +1106,7 @@ class NmapParserSAX(ParserBasics, ContentHandler):
fd.close() fd.close()
def _write_output(self, writer): def _write_output(self, writer):
if self._nmap_output is None: if self.nmap_output == "":
return return
writer.startElement("output", Attributes({"type": "interactive"})) writer.startElement("output", Attributes({"type": "interactive"}))
writer.characters(self.nmap_output) writer.characters(self.nmap_output)