Skip to content

Instantly share code, notes, and snippets.

@ott3rly
Created February 20, 2024 09:50
Show Gist options
  • Save ott3rly/7bd162b1f2de4dcf3d65de07a530a326 to your computer and use it in GitHub Desktop.
Save ott3rly/7bd162b1f2de4dcf3d65de07a530a326 to your computer and use it in GitHub Desktop.
Convert nmap xml output suitable for httpx
#!/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