问题
Is there a way In bash to determine if a URL uses SSL? Before I send anything else to the URL I want to find out if it only accepts HTTP or HTTPS connections.
回答1:
You can use the below script if you have access to wget.
#/bin/bash
URL=google.com
if wget --spider https://$URL 2>/dev/null; then
echo "https is present"
else
echo "https not present"
fi
Please note that you need to have http_proxy / https_proxy set.
I tested the above script in cygwin64 [dont have access to nix system as of now]
You should be also able to modify the same script using curl.
回答2:
http
if [[ $(wget -S --spider http://yoursite 2>&1 | grep 'HTTP/1.1 200 OK') ]]; \ then echo "true"; fihttps
if [[ $(wget -S --spider https://yoursite 2>&1 | grep 'HTTP/1.1 200 OK') ]]; \ then echo "true"; fi
来源:https://stackoverflow.com/questions/39168736/using-bash-to-determine-if-url-is-http-or-https