You are not logged in.

#1 2014-08-05 12:40:24

hauntedbyshadow
Member
Registered: 2014-07-02
Posts: 19
Website

[solved] SSL check

Hey guys, so i'm not sure the syntax on this but I have the base ready. So what i'm doing is making a script to check for SSL's on a domain.  So I have this

 #/bin/bash

for dir in $(ls)

do
        echo $dir
        curl -Iv https://$dir --connect-timeout 5

done 

Just not sure how to get it to only show me if it has a ssl or not, I was thinking some sort of if elif using a grep for 'SSL connect error' but not sure on the syntax to do so any suggestions? 
thanks big_smile

Last edited by hauntedbyshadow (2014-08-05 14:41:51)

Offline

#2 2014-08-05 13:56:56

x33a
Forum Fellow
Registered: 2009-08-15
Posts: 4,587

Re: [solved] SSL check

When you try to connect to a server which doesn't support https, you'll get a connection refused error, for example:

$ curl -I https://distrowatch.com
curl: (7) Failed to connect to distrowatch.com port 443: Connection refused

So you can just check for the exit status and print a statement accordingly.

Here's one example script:

#!/usr/bin/env bash

urls=(https://distrowatch.com https://sphinx-doc.org https://www.archlinux.org)

for url in ${urls[@]}; do
    curl -I "$url" > /dev/null 2>&1
    if [[ $? -ne 7 ]]; then
        echo "SSL present for $url"
    else
        echo "SSL not present for $url"
    fi
done

Note: urls above is an array, and you'll need to separate the actual urls using spaces.

Last edited by x33a (2014-08-05 13:57:22)

Offline

#3 2014-08-05 14:41:32

hauntedbyshadow
Member
Registered: 2014-07-02
Posts: 19
Website

Re: [solved] SSL check

Wow that is exactly what I was looking for brilliant, Thanks a bunch big_smile

Offline

Board footer

Powered by FluxBB