@@ -82,8 +82,9 @@ def _parse_xml(cls, nmap_data=None, incomplete=False):
8282 raise NmapParserException ("wrong nmap_data type given as "
8383 "argument: cannot parse data" )
8484
85- if incomplete :
85+ if incomplete is True :
8686 nmap_data += "</nmaprun>"
87+
8788 try :
8889 root = ET .fromstring (nmap_data )
8990 except :
@@ -137,7 +138,7 @@ def _parse_xml_report(cls, root=None):
137138 return NmapReport (nmap_scan )
138139
139140 @classmethod
140- def parse_fromstring (cls , nmap_data , data_type = "XML" ):
141+ def parse_fromstring (cls , nmap_data , data_type = "XML" , incomplete = False ):
141142 """
142143 Call generic cls.parse() method and ensure that a string is
143144 passed on as argument. If not, an exception is raised.
@@ -150,16 +151,23 @@ def parse_fromstring(cls, nmap_data, data_type="XML"):
150151
151152 :param data_type: Specifies the type of data passed on as argument.
152153
154+ :param incomplete: enable you to parse interrupted nmap scans
155+ and/or incomplete nmap xml blocks by adding a </nmaprun> at
156+ the end of the scan.
157+ :type incomplete: boolean
158+
153159 :return: NmapObject
154160 """
155161
156162 if not isinstance (nmap_data , str ):
157163 raise NmapParserException ("bad argument type for "
158164 "xarse_fromstring(): should be a string" )
159- return cls .parse (nmap_data , data_type )
165+ return cls .parse (nmap_data , data_type , incomplete )
160166
161167 @classmethod
162- def parse_fromfile (cls , nmap_report_path , data_type = "XML" ):
168+ def parse_fromfile (cls , nmap_report_path ,
169+ data_type = "XML" ,
170+ incomplete = False ):
163171 """
164172 Call generic cls.parse() method and ensure that a correct file
165173 path is given as argument. If not, an exception is raised.
@@ -173,13 +181,18 @@ def parse_fromfile(cls, nmap_report_path, data_type="XML"):
173181
174182 :param data_type: Specifies the type of serialization in the file.
175183
184+ :param incomplete: enable you to parse interrupted nmap scans
185+ and/or incomplete nmap xml blocks by adding a </nmaprun> at
186+ the end of the scan.
187+ :type incomplete: boolean
188+
176189 :return: NmapObject
177190 """
178191
179192 try :
180193 with open (nmap_report_path , 'r' ) as fileobj :
181194 fdata = fileobj .read ()
182- rval = cls .parse (fdata , data_type )
195+ rval = cls .parse (fdata , data_type , incomplete )
183196 except IOError :
184197 raise
185198 return rval
0 commit comments