Skip to content

Commit 35f4918

Browse files
committed
fix(extraports): added support for extra ports, fixes #40
1 parent cd3ffbd commit 35f4918

File tree

5 files changed

+396
-38
lines changed

5 files changed

+396
-38
lines changed

libnmap/objects/host.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -463,35 +463,13 @@ def id(self):
463463
return self.address
464464

465465
@property
466-
def extraports_state(self):
466+
def extraports(self):
467467
"""
468-
dictionnary containing state and amount of extra ports scanned
469-
for which a common state, usually, closed was discovered.
468+
Returns a list of NmapExtraPort objects
470469
471-
:return: dict with keys 'state' and 'count' or None
470+
:return: list of NmapExtraPort objects
472471
"""
473-
rval = None
474-
_xports = self._extras.get('extraports', None)
475-
476-
if _xports is not None:
477-
rval = {'state': _xtrports['state'], 'count': _xtrports['count']}
478-
479-
return rval
480-
481-
@property
482-
def extraports_reasons(self):
483-
"""
484-
dictionnary containing reasons why extra ports scanned
485-
for which a common state, usually, closed was discovered.
486-
487-
:return: array of dict containing keys 'state' and 'count' or None
488-
"""
489-
r = self._extras.get("extraports", {})
490-
491-
if r is None:
492-
return None
493-
494-
return r.get("reasons", None)
472+
return self._extraports
495473

496474
def get_dict(self):
497475
"""

libnmap/objects/service.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ def __init__(self, xdict):
388388
self._reasons = xdict.get('reasons', [])
389389

390390
@property
391-
def count(self):
391+
def extra_count(self):
392392
"""
393393
Accessor for the number of extraports
394394
@@ -397,7 +397,7 @@ def count(self):
397397
return int(self._count)
398398

399399
@property
400-
def state(self):
400+
def extra_state(self):
401401
"""
402402
Accessor for the state of extraports listed
403403
@@ -406,11 +406,11 @@ def state(self):
406406
return self._state
407407

408408
@property
409-
def reason(self):
409+
def extra_reasons(self):
410410
"""
411411
Return the first reason available for the extraport listed.
412412
413413
:return: dict, empty if no extraports reason available
414414
"""
415415

416-
return self.reasons[0] if len(self.reasons) else {}
416+
return self._reasons

libnmap/parser.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,6 @@ def _parse_xml_ports(cls, scanports_data):
391391
elif xservice.tag == "extraports":
392392
extraports = cls.__parse_extraports(xservice)
393393
rdict['extraports'].append(extraports)
394-
# DEBUG REMOVE ME
395-
else:
396-
print "struct port unknown attr: %s value: %s" %
397-
(h.tag, h.get(h.tag))
398394
return rdict
399395

400396
@classmethod
@@ -477,10 +473,8 @@ def __parse_extraports(cls, extraports_data):
477473
xelement = cls.__format_element(extraports_data)
478474
extraports_dict = cls.__format_attributes(xelement)
479475

480-
if "state" in extraports_dict:
481-
rdict["state"] = extraports_dict
482-
if "count" in extraports_dict:
483-
rdict["count"] = extraports_dict
476+
rdict["state"] = extraports_dict.get("state", None)
477+
rdict["count"] = extraports_dict.get("count", None)
484478
for xelt in xelement:
485479
if xelt.tag == "extrareasons":
486480
extrareasons_dict = cls.__format_attributes(xelt)

0 commit comments

Comments
 (0)