Skip to content

Instantly share code, notes, and snippets.

@groundcat
Last active July 16, 2023 21:06
Show Gist options
  • Save groundcat/d6fd5492c58763d682aa0ecb23679f42 to your computer and use it in GitHub Desktop.
Save groundcat/d6fd5492c58763d682aa0ecb23679f42 to your computer and use it in GitHub Desktop.
CDN and Load Balancer Tester

CDN and Load Balancer Tester

This script checks the SSL installation and page title consistency across all the IP addresses resolved by a given domain. It can be used to test the configuration of CDNs (Content Delivery Networks) and load balancers.

Prerequisites

This script uses bash, curl, openssl and dig, make sure they are installed on your system before running the script.

Usage

To use the script, follow the steps below:

  1. Save the script into a file named check.sh.
  2. Make the script executable by running the command chmod +x check.sh.
  3. Run the script with your domain as an argument: ./check.sh example.com.

How it Works

The script does the following for each IP address resolved from the given domain:

  1. It checks if SSL is properly installed.
  2. It fetches and prints the website title.

It only considers IP addresses in the resolution, CNAMEs are ignored.

The script prints an error message and exits with a non-zero status if SSL is not properly installed on an IP address, or if the titles from different IP addresses do not match.

Limitations

  1. This script assumes that SSL is installed on port 443.
  2. It expects the title to be on a single line and only one title per page.

License

This script is released under the MIT license.

#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "Usage: ./check.sh [domain]"
exit 1
fi
DOMAIN=$1
ALL_RECORDS=$(dig @8.8.8.8 +short $DOMAIN)
echo "resolving $DOMAIN"
# Filter only IP addresses
IPS=$(echo "$ALL_RECORDS" | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}')
echo "found following ip addresses resolved by $DOMAIN"
echo "$IPS"
previous_title=""
is_first=1
for IP in $IPS
do
echo ""
echo "testing $DOMAIN ($IP) ..."
# Check if SSL is properly installed
if echo | openssl s_client -servername $DOMAIN -connect $IP:443 2>/dev/null | \
openssl x509 -noout > /dev/null 2>&1 ; then
echo "SSL is properly installed"
else
echo "SSL is NOT properly installed"
exit 1
fi
# Check website title
title=$(curl -s -k --resolve $DOMAIN:443:$IP https://$DOMAIN | \
grep -o '<title>.*</title>' | sed 's/<title>\(.*\)<\/title>/\1/')
echo "<title>$title</title>"
if ((is_first)) ; then
previous_title=$title
is_first=0
elif [ "$previous_title" != "$title" ] ; then
echo "website titles do not match"
exit 1
fi
done
echo ""
echo "all website titles match"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment