Check domains
Posted on 2021-09-22 in Trucs et astuces
Here is a small script to allow you to easily check that a domain your manage is correct (ie responds correctly, is available with IPv4 and IPv6, only supports TLS 1.2+…). It even has some color built in! You can of course adapt it to fit your needs.
You can use it like this:
./check-domains.sh www.jujens.eu
And you should get something like that:
---- Checking domain www.jujens.eu Redirect to HTTPS: OK Is reachable with IPv4: OK Is reachable with IPv6: OK Check HTTP 1.1: OK Check HTTP2: OK Check not reachable with TLS 1.0: OK Check not reachable with TLS 1.1: OK Check reachable with TLS 1.2: OK Check not reachable with TLS 1.3: OK Check that server responds with 200 or 404: OK
The script (direct link):
1 #!/usr/bin/env bash 2 3 readonly red="\e[0;91m" 4 readonly blue="\e[0;94m" 5 readonly expand_bg="\e[K" 6 readonly blue_bg="\e[0;104m${expand_bg}" 7 readonly red_bg="\e[0;101m${expand_bg}" 8 readonly green_bg="\e[0;102m${expand_bg}" 9 readonly green="\e[0;92m" 10 readonly white="\e[0;97m" 11 readonly bold="\e[1m" 12 readonly uline="\e[4m" 13 readonly reset="\e[0m" 14 15 16 function ok() { 17 echo -e "${green}OK${reset}" 18 } 19 20 function nok() { 21 echo -e "${red}NOK${reset}" 22 } 23 24 function main() { 25 for domain in "$@"; do 26 echo -e "${bold}---- Checking domain ${domain}${reset}" 27 28 echo -n "Redirect to HTTPS: " 29 if curl --head --silent "http://${domain}" | grep --silent Location; then 30 ok 31 else 32 nok 33 fi 34 35 echo -n "Is reachable with IPv4: " 36 if curl -4 --head --silent "https://${domain}" > /dev/null; then 37 ok 38 else 39 nok 40 fi 41 42 echo -n "Is reachable with IPv6: " 43 if curl -6 --head --silent "https://${domain}" > /dev/null; then 44 ok 45 else 46 nok 47 fi 48 49 echo -n "Check HTTP 1.1: " 50 if curl --http1.1 --silent "https://${domain}" > /dev/null; then 51 ok 52 else 53 nok 54 fi 55 56 echo -n "Check HTTP2: " 57 if curl --http2 --silent "https://${domain}" > /dev/null; then 58 ok 59 else 60 nok 61 fi 62 63 echo -n "Check not reachable with TLS 1.0: " 64 if ! curl --tlsv1.0 --tls-max 1.0 --silent "https://${domain}" > /dev/null; then 65 ok 66 else 67 nok 68 fi 69 70 echo -n "Check not reachable with TLS 1.1: " 71 if ! curl --tlsv1.1 --tls-max 1.1 --silent "https://${domain}" > /dev/null; then 72 ok 73 else 74 nok 75 fi 76 77 echo -n "Check reachable with TLS 1.2: " 78 if curl --tlsv1.2 --tls-max 1.2 --silent "https://${domain}" > /dev/null; then 79 ok 80 else 81 nok 82 fi 83 84 echo -n "Check not reachable with TLS 1.3: " 85 if curl --tlsv1.3 --tls-max 1.3 --silent "https://${domain}" > /dev/null; then 86 ok 87 else 88 nok 89 fi 90 91 echo -n "Check that server responds with 200 or 404: " 92 status_code=$(curl --write "%{http_code}" --silent --head --output /dev/null "https://${domain}") 93 if [[ "${status_code}" == '200' || "${status_code}" == '404' ]]; then 94 ok 95 else 96 nok 97 fi 98 99 echo -e "" 100 done 101 } 102 103 main "$@"