Last active
January 8, 2022 18:20
-
-
Save david-botelho-mariano/ca13d2ce0cbaea1ced5daa6917d11a4d to your computer and use it in GitHub Desktop.
parse nmap result to "ip: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("result.xml") | |
hosts = xmldoc.getElementsByTagName("host") | |
for host in hosts: | |
addresses = host.getElementsByTagName("address") | |
for address in addresses: | |
ip = address.attributes["addr"] | |
ip = ip.value | |
#print("IP:%s"%(ip)) | |
ports = host.getElementsByTagName("ports") | |
for port in ports: | |
port = host.getElementsByTagName("port") | |
for port in port: | |
port = port.attributes["portid"] | |
port = port.value | |
print(ip + ":" + port) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment