Last active
January 31, 2019 20:11
-
-
Save 003random/71f36ae7f78d2fc36a136f8a71ed0029 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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