Created
January 8, 2022 18:22
-
-
Save david-botelho-mariano/9f189d52c6db301f72a490d555b9d527 to your computer and use it in GitHub Desktop.
parse nmap result to "domain:port" format (nmap example.com -oX result.xml)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from xml.dom import minidom | |
xmldoc = minidom.parse("nmap.xml") | |
hosts = xmldoc.getElementsByTagName("host") | |
for host in hosts: | |
hostnames = host.getElementsByTagName("hostnames") | |
for hostname in hostnames: | |
hostname = hostname.getElementsByTagName("hostname") | |
hostname = hostname[0].attributes["name"].value | |
#print(hostname) | |
ports = host.getElementsByTagName("ports") | |
for port in ports: | |
port = host.getElementsByTagName("port") | |
for port in port: | |
port = port.attributes["portid"] | |
port = port.value | |
print(hostname + ":" + port) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment