Skip to content

Instantly share code, notes, and snippets.

@ott3rly
Created February 20, 2024 09:50
Show Gist options
  • Select an option

  • Save ott3rly/7bd162b1f2de4dcf3d65de07a530a326 to your computer and use it in GitHub Desktop.

Select an option

Save ott3rly/7bd162b1f2de4dcf3d65de07a530a326 to your computer and use it in GitHub Desktop.

Revisions

  1. ott3rly created this gist Feb 20, 2024.
    17 changes: 17 additions & 0 deletions nmap-xml-to-httpx.sh
    Original 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