Skip to content

Instantly share code, notes, and snippets.

@mzet-
Created April 6, 2020 14:49
Show Gist options
  • Save mzet-/7ea36cd74cf62a91fe7f5f07641188a6 to your computer and use it in GitHub Desktop.
Save mzet-/7ea36cd74cf62a91fe7f5f07641188a6 to your computer and use it in GitHub Desktop.
Scrape http/https ports from Nmap's output
#/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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment