Using Bash to determine if URL is HTTP or HTTPS

拟墨画扇 提交于 2019-12-24 08:34:13

问题


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";  fi
    
  • https

    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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!