Skip to content

Instantly share code, notes, and snippets.

@co60ca
Created July 4, 2017 03:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save co60ca/b56032c7d1ee31a1861f65761746d20d to your computer and use it in GitHub Desktop.
Save co60ca/b56032c7d1ee31a1861f65761746d20d to your computer and use it in GitHub Desktop.
check-sni.sh
#!/bin/bash
# This script uses curl / tshark to check if a server accepts
# and responds with SNI (server_name) in server hello
# exits 1 if not SNI, exits 0 if SNI
set -eu
hostname=$1
# Tempfile for formatted output
tmpfile="$(mktemp)"
tshark -V -f "(host $hostname and port 443)" \
-Y "ssl.handshake.type == 2" 2>/dev/null 1>"$tmpfile" &
pid=$!
# Wait for tshark setup
sleep 1
# Send a request to get a server hello
curl --silent "https://${hostname}" 2> /dev/null 1>&2
# Make sure tshark has time to read it
sleep 1
# Check if server_name is set
res=$(grep server_name "$tmpfile")
# Kill our tshark
kill "$pid"
# Remove our temp file
rm "$tmpfile"
if [ "$res" ] ; then
echo "$hostname"
exit 0
fi
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment