Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
maurosoria
GitHub Repository: maurosoria/dirsearch
Path: blob/master/lib/parse/nmap.py
896 views
1
from __future__ import annotations
2
3
import defusedxml.ElementTree as ET
4
5
6
def parse_nmap(file: str) -> list[str]:
7
root = ET.parse(file).getroot()
8
targets = []
9
for host in root.iter("host"):
10
hostname = (
11
host.find("hostnames").find("hostname").get("name")
12
or host.find("address").get("addr")
13
)
14
targets.extend(
15
f"{hostname}:{port.get('portid')}"
16
for port in host.find("ports").iter("port")
17
if (
18
port.get("protocol") == "tcp" # UDP is not used in HTTP because it is not a "reliable transport"
19
and port.find("state").get("state") == "open"
20
and port.find("service").get("name") in ["http", "unknown"]
21
)
22
)
23
24
return targets
25
26