Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/preflight_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: psf/black@stable
with:
options: "--check -l 79 --exclude docs/"
version: "22.8.0"
version: "24.3.0"
- name: Format checker with isort
run: isort --check-only -m 3 -l 79 --profile=black .
- name: Lint with flake8
Expand All @@ -37,7 +37,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v4
- name: Setup Python ${{ matrix.python-version }}
Expand Down
53 changes: 32 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
exclude: ^(test/|.tox/|docs)
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.8.0
hooks:
- id: black
args: [--line-length=79]
files: ^libnmap
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.6.4
hooks:
- id: isort
args: [--multi-line=3, --line-length=79, --profile=black]
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
hooks:
- id: flake8
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 24.3.0
hooks:
- id: black
args: [--line-length=79]
files: ^libnmap
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.6.4
hooks:
- id: isort
args: [--multi-line=3, --line-length=79, --profile=black]
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
hooks:
- id: flake8
exclude: ^libnmap/(test/|docs/|examples/)
- repo: local
hooks:
- id: pytest-check
name: pytest-check
stages: [pre-commit]
types: [python]
entry: pytest --cov=libnmap/ --ignore=libnmap/test/test_backend_plugin_factory.py
language: system
pass_filenames: false
always_run: true
31 changes: 6 additions & 25 deletions libnmap/objects/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(
self._status = status if status is not None else {}
self._services = services if services is not None else []
self._extras = extras if extras is not None else {}
self._extraports = self._extras.get("extraports", None)
self._osfingerprinted = False
self.os = None
if "os" in self._extras:
Expand Down Expand Up @@ -462,34 +463,14 @@ def id(self):
return self.address

@property
def extraports_state(self):
def extraports(self):
"""
dictionnary containing state and amount of extra ports scanned
for which a common state, usually, closed was discovered.
Returns a list of extraport dict with
with struct { count: "123", state: "filtered, extrareasons: [{}] }

:return: dict with keys 'state' and 'count' or None
:return: list of extraport dict
"""
_xtrports = self._extras.get("extraports", None)

if _xtrports is None:
return None

return {"state": _xtrports["state"], "count": _xtrports["count"]}

@property
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' or None
"""
r = self._extras.get("extraports", {})

if r is None:
return None

return r.get("reasons", None)
return self._extraports

def get_dict(self):
"""
Expand Down
19 changes: 7 additions & 12 deletions libnmap/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,17 +385,14 @@ def _parse_xml_ports(cls, scanports_data):

xelement = cls.__format_element(scanports_data)

rdict = {"ports": [], "extraports": None}
rdict = {"ports": [], "extraports": []}
for xservice in xelement:
if xservice.tag == "port":
nport = cls._parse_xml_port(xservice)
rdict["ports"].append(nport)
elif xservice.tag == "extraports":
extraports = cls.__parse_extraports(xservice)
rdict["extraports"] = extraports
# else:
# print "struct port unknown attr: %s value: %s" %
# (h.tag, h.get(h.tag))
rdict["extraports"].append(extraports)
return rdict

@classmethod
Expand Down Expand Up @@ -472,20 +469,18 @@ def __parse_extraports(cls, extraports_data):
:param extraports_data: XML data for extraports
:type extraports_data: xml.ElementTree.Element or a string

:return: python dict with following keys: state, count, reason
:return: python dict with following keys: state, count, reasons
"""
rdict = {"state": "", "count": "", "reasons": []}
rdict = {"state": "", "count": "", "extrareasons": []}
xelement = cls.__format_element(extraports_data)
extraports_dict = cls.__format_attributes(xelement)

if "state" in extraports_dict:
rdict["state"] = extraports_dict
if "count" in extraports_dict:
rdict["count"] = extraports_dict
rdict["state"] = extraports_dict.get("state", None)
rdict["count"] = extraports_dict.get("count", None)
for xelt in xelement:
if xelt.tag == "extrareasons":
extrareasons_dict = cls.__format_attributes(xelt)
rdict["reasons"].append(extrareasons_dict)
rdict["extrareasons"].append(extrareasons_dict)
return rdict

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion libnmap/test/files/2_hosts.json

Large diffs are not rendered by default.

Loading