Skip to content

Instantly share code, notes, and snippets.

@mzet-
Created April 6, 2020 14:49
Show Gist options
  • Select an option

  • Save mzet-/7ea36cd74cf62a91fe7f5f07641188a6 to your computer and use it in GitHub Desktop.

Select an option

Save mzet-/7ea36cd74cf62a91fe7f5f07641188a6 to your computer and use it in GitHub Desktop.

Revisions

  1. mzet- created this gist Apr 6, 2020.
    26 changes: 26 additions & 0 deletions gnmap2service.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #/bin/bash

    INPUT="$1"

    while read l; do
    IP=$(cut -d' ' -f2 <<< "$l");
    httpPorts1=$(echo "$l" | grep -P -o '[0-9]{1,5}/open/tcp//http//.*?/')
    httpPorts2=$(echo "$l" | grep -P -o '[0-9]{1,5}/open/tcp//ssl\|http//.*?/')
    httpPorts3=$(echo "$l" | grep -P -o '[0-9]{1,5}/open/tcp//ssl\|https//.*?/')
    httpPorts4=$(echo "$l" | grep -P -o '[0-9]{1,5}/open/tcp//ssl\|https\?//.*?/')
    #httpPorts3=$(echo "$l" | grep -P -o '[0-9]{1,5}/open/tcp//http//.*?/')
    while read t; do
    port=$(echo "$t" | awk -F'//' '{print $1}' | cut -d'/' -f1)
    if [ -n "$t" ]; then

    if [ $port == 80 ]; then echo "http://$IP:$port"
    elif [ $port == 443 ]; then echo "https://$IP"
    else
    echo "http://$IP:$port"
    echo "https://$IP:$port"
    fi
    fi
    #[ -n "$t" ] && echo "https://$IP:$port"
    done <<< $(grep 'Microsoft HTTPAPI httpd 2.0 (SSDP|UPnP)' -v <<< "${httpPorts1}${httpPorts2}${httpPorts3}${httpPorts4}")
    #[ "$?" = 0 ] && echo $(cut -d' ' -f2 <<< "$l");
    done < "$INPUT"