Skip to content

Commit

Permalink
Merge pull request #65 from jack8daniels2/master
Browse files Browse the repository at this point in the history
Fix parsing of nmap script output with multiple elements or tables
  • Loading branch information
savon-noir committed Oct 25, 2015
2 parents ab6bc9b + ccd8838 commit fe62f7b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions libnmap/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,22 @@ def __parse_script(cls, script_data):
elif script_elem.tag == 'table':
tdict = {}
for telem in script_elem:
tdict[telem.get('key')] = telem.text
_elt_dict[script_elem.get('key')] = tdict
# Handle duplicate element keys
tkey = telem.get('key')
if tkey in tdict:
if not isinstance(tdict[tkey], list):
tdict[tkey] = [tdict[tkey], ]
tdict[tkey].append(telem.text)
else:
tdict[tkey] = telem.text
# Handle duplicate table keys
skey = script_elem.get('key')
if skey in _elt_dict:
if not isinstance(_elt_dict[skey], list):
_elt_dict[skey] = [_elt_dict[skey], ]
_elt_dict[skey].append(tdict)
else:
_elt_dict[skey] = tdict
_script_dict['elements'] = _elt_dict
return _script_dict

Expand Down

0 comments on commit fe62f7b

Please sign in to comment.