Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Bash to determine if URL is HTTP or HTTPS

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.

like image 862
john Avatar asked Feb 28 '26 23:02

john


1 Answers

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.

like image 51
Saptarshi Avatar answered Mar 03 '26 16:03

Saptarshi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!