Skip to content

Commit fe62f7b

Browse files
committed
Merge pull request savon-noir#65 from jack8daniels2/master
Fix parsing of nmap script output with multiple elements or tables
2 parents ab6bc9b + ccd8838 commit fe62f7b

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

libnmap/parser.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,22 @@ def __parse_script(cls, script_data):
473473
elif script_elem.tag == 'table':
474474
tdict = {}
475475
for telem in script_elem:
476-
tdict[telem.get('key')] = telem.text
477-
_elt_dict[script_elem.get('key')] = tdict
476+
# Handle duplicate element keys
477+
tkey = telem.get('key')
478+
if tkey in tdict:
479+
if not isinstance(tdict[tkey], list):
480+
tdict[tkey] = [tdict[tkey], ]
481+
tdict[tkey].append(telem.text)
482+
else:
483+
tdict[tkey] = telem.text
484+
# Handle duplicate table keys
485+
skey = script_elem.get('key')
486+
if skey in _elt_dict:
487+
if not isinstance(_elt_dict[skey], list):
488+
_elt_dict[skey] = [_elt_dict[skey], ]
489+
_elt_dict[skey].append(tdict)
490+
else:
491+
_elt_dict[skey] = tdict
478492
_script_dict['elements'] = _elt_dict
479493
return _script_dict
480494

0 commit comments

Comments
 (0)