Created
February 20, 2024 09:50
-
-
Save ott3rly/7bd162b1f2de4dcf3d65de07a530a326 to your computer and use it in GitHub Desktop.
Revisions
-
ott3rly created this gist
Feb 20, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ #!/bin/bash # Check if an argument was provided if [ $# -eq 0 ]; then NMAP_XML_OUTPUT="/dev/stdin" else NMAP_XML_OUTPUT="$1" fi # Use xmllint to parse IP addresses and ports from the Nmap XML output xmllint --xpath '//host[status/@state="up"]/address[@addrtype="ipv4"]/@addr' $NMAP_XML_OUTPUT | \ sed 's/ addr="/\n/g' | sed 's/"//g' | grep -v '^$' | while read IP; do xmllint --xpath "//host[address/@addr=\"$IP\"]/ports/port[state/@state='open']/@portid" $NMAP_XML_OUTPUT | \ sed 's/ portid="/\n/g' | sed 's/"//g' | grep -v '^$' | while read PORT; do echo "$IP:$PORT" done done