Last active
December 12, 2023 13:33
-
-
Save thomaspatzke/3d095150fbf52d3e69006aed99fb3e9d to your computer and use it in GitHub Desktop.
Extract all open ports in Host:Port format from nmap XML output
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
xmlstarlet sel -t -m '//port/state[@state="open"]/parent::port' -v 'ancestor::host/address/@addr' -o : -v './@portid' -n nmap-output.xml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the snippet @thomaspatzke! I didn't know about xmlstarlet, which turns out to be a very useful tool for parsing and searching for data through an XML tree. As a side note, your code writes in the format
IP:port
. If anybody is interested in the formatDOMAIN:port
, it is as simple as changing:'ancestor::host/address/@addr'
for:
'ancestor::host/hostnames/hostname[@type="user"]/@name'
See this fork for the whole snippet.