Skip to content

Instantly share code, notes, and snippets.

@003random
Last active January 31, 2019 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 003random/71f36ae7f78d2fc36a136f8a71ed0029 to your computer and use it in GitHub Desktop.
Save 003random/71f36ae7f78d2fc36a136f8a71ed0029 to your computer and use it in GitHub Desktop.
domain="poc-server.com"
for port in `sed '/^$/d' "ports.txt"`; do
url="$domain:$port"
http=false
https=false
protocol=""
if [[ $(echo "http://$url" | online) ]]; then http=true; else http=false; fi
if [[ $(echo "https://$url" | online) ]]; then https=true; else https=false; fi
if [[ "$http" = true ]]; then protocol="http"; fi
if [[ "$https" = true ]]; then protocol="https"; fi
if [[ "$http" = true && "$https" = true ]]; then
# If the content length of http is greater than the content length of https, then we choose http, otherwise we go with https
contentLengthHTTP=$(curl -s http://$url | wc -c)
contentLengthHTTPS=$(curl -s https://$url | wc -c)
if [[ "$contentLengthHTTP" -gt "$contentLengthHTTPS" ]]; then protocol="http"; else protocol="https"; fi
if [[ "$port" == "80" ]]; then protocol="http"; fi
if [[ "$port" == "443" ]]; then protocol="https"; fi
fi
if [[ ! -z "$protocol" ]]; then
echo "$protocol://$domain:$port"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment