Created
February 20, 2024 09:50
-
-
Save ott3rly/7bd162b1f2de4dcf3d65de07a530a326 to your computer and use it in GitHub Desktop.
Convert nmap xml output suitable for httpx
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 characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment