#!/bin/bash
export LC_ALL=C
echo "===== TLS HANDSHAKE: same edge IP, different SNI ====="
for sni in www.cloudflare.com cloudflare-ech.com one.one.one.one snip.edgeoneai.cc.cd lucasjow.us.ci; do
  printf '  SNI %-24s @188.114.97.6 -> ' "$sni"
  curl -sk -o /dev/null -w '%{http_code} %{time_total}s\n' --max-time 10 \
    --resolve "$sni:443:188.114.97.6" "https://$sni/" 2>/dev/null || echo "fail"
done

echo
echo "===== RAW TLS HANDSHAKE (openssl, no HTTP) ====="
for sni in www.cloudflare.com snip.edgeoneai.cc.cd; do
  printf '  %-24s -> ' "$sni"
  if timeout 8 bash -c "echo | openssl s_client -connect 188.114.98.0:443 -servername $sni -brief 2>&1 | head -3 | tr '\n' ' '" 2>/dev/null; then echo; else echo TIMEOUT; fi
done

echo
echo "===== 1.1.1.1 / OTHER CF IPs WITH BENIGN SNI ====="
for ip in 1.1.1.1 104.16.0.1; do
  printf '  %-14s SNI=www.cloudflare.com -> ' "$ip"
  curl -sk -o /dev/null -w '%{http_code} %{time_total}s\n' --max-time 10 \
    --resolve "www.cloudflare.com:443:$ip" https://www.cloudflare.com/ 2>/dev/null || echo fail
done
