From a9ba459d02ce7b51311f5903f5f5d23ed008675c Mon Sep 17 00:00:00 2001 From: orf Date: Mon, 8 Sep 2014 12:24:05 +0100 Subject: [PATCH 1/3] Fix TypeError in extraports_* functions Sometimes there is no extraports tag. In this case a TypeError is raised, which is confusing. Either a proper exception (MissingExtraports or something) should be raised, or None returned. This patch does the latter. --- libnmap/objects/host.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/libnmap/objects/host.py b/libnmap/objects/host.py index 03181c9..391b80f 100644 --- a/libnmap/objects/host.py +++ b/libnmap/objects/host.py @@ -434,9 +434,12 @@ def extraports_state(self): dictionnary containing state and amount of extra ports scanned for which a common state, usually, closed was discovered. - :return: dict with keys 'state' and 'count' + :return: dict with keys 'state' and 'count' or None """ _xtrports = self._extras['extraports'] + if _xtrports is None: + return None + return {'state': _xtrports['state'], 'count': _xtrports['count']} @property @@ -445,9 +448,13 @@ def extraports_reasons(self): dictionnary containing reasons why extra ports scanned for which a common state, usually, closed was discovered. - :return: array of dict containing keys 'state' and 'count' + :return: array of dict containing keys 'state' and 'count' or None """ - return self._extras['extraports']['reasons'] + r = self._extras['extraports'] + if r is None: + return None + + return r['reasons'] def get_dict(self): """ From ba3ae6ff0904511ac5e0f49eef8863382b2ca61f Mon Sep 17 00:00:00 2001 From: orf Date: Mon, 8 Sep 2014 12:26:36 +0100 Subject: [PATCH 2/3] Update host.py --- libnmap/objects/host.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libnmap/objects/host.py b/libnmap/objects/host.py index 391b80f..f45ce8e 100644 --- a/libnmap/objects/host.py +++ b/libnmap/objects/host.py @@ -436,7 +436,7 @@ def extraports_state(self): :return: dict with keys 'state' and 'count' or None """ - _xtrports = self._extras['extraports'] + _xtrports = self._extras.get('extraports', None) if _xtrports is None: return None @@ -450,7 +450,7 @@ def extraports_reasons(self): :return: array of dict containing keys 'state' and 'count' or None """ - r = self._extras['extraports'] + r = self._extras.get('extraports', None) if r is None: return None From 7be7f5950f997bd56f1f3d10b37a6c4a5af07c20 Mon Sep 17 00:00:00 2001 From: orf Date: Thu, 11 Sep 2014 10:55:35 +0100 Subject: [PATCH 3/3] Update host.py --- libnmap/objects/host.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/libnmap/objects/host.py b/libnmap/objects/host.py index f45ce8e..3706ec4 100644 --- a/libnmap/objects/host.py +++ b/libnmap/objects/host.py @@ -437,9 +437,10 @@ def extraports_state(self): :return: dict with keys 'state' and 'count' or None """ _xtrports = self._extras.get('extraports', None) + if _xtrports is None: return None - + return {'state': _xtrports['state'], 'count': _xtrports['count']} @property @@ -450,11 +451,9 @@ def extraports_reasons(self): :return: array of dict containing keys 'state' and 'count' or None """ - r = self._extras.get('extraports', None) - if r is None: - return None - - return r['reasons'] + r = self._extras.get('extraports', {}) + + return r.get('reasons', None) def get_dict(self): """