#!/bin/bash
export LC_ALL=C
printf '\n----- TCP REACHABILITY TO CLOUDFLARE EDGE IPs -----\n'
for ip in 188.114.98.0 188.114.97.6 104.21.91.244 172.67.155.65 104.16.0.1 1.1.1.1; do
  printf '  %-16s :443 -> ' "$ip"
  if timeout 6 bash -c "exec 3<>/dev/tcp/$ip/443" 2>/dev/null; then echo OPEN; else echo BLOCKED/TIMEOUT; fi
done

printf '\n----- TCP :80 -----\n'
for ip in 188.114.98.0 104.21.91.244; do
  printf '  %-16s :80  -> ' "$ip"
  if timeout 6 bash -c "exec 3<>/dev/tcp/$ip/80" 2>/dev/null; then echo OPEN; else echo BLOCKED/TIMEOUT; fi
done

printf '\n----- TLS VIA EDGE IP (Host = sni) -----\n'
for pair in "snip.edgeoneai.cc.cd:188.114.98.0" "lucasjow.us.ci:188.114.97.6" "www.volumeroot.com:188.114.98.0"; do
  host=${pair%%:*}; ip=${pair##*:}
  printf '  %-26s @ %-15s -> ' "$host" "$ip"
  curl -sk -o /dev/null -w '%{http_code} %{time_total}s\n' --max-time 10 \
    --resolve "$host:443:$ip" "https://$host/" 2>/dev/null || echo "fail"
done

printf '\n----- CONTROL: normal cloudflare domain -----\n'
printf '  cloudflare.com  -> '; curl -s -o /dev/null -w '%{http_code} %{time_total}s\n' --max-time 10 https://cloudflare.com/ 2>/dev/null
printf '  gstatic.com     -> '; curl -s -o /dev/null -w '%{http_code} %{time_total}s\n' --max-time 10 https://www.gstatic.com/generate_204 2>/dev/null

printf '\n----- DNS OF THE SNI HOSTS -----\n'
for h in snip.edgeoneai.cc.cd lucasjow.us.ci www.volumeroot.com; do
  printf '  %-26s -> %s\n' "$h" "$(getent ahostsv4 "$h" 2>/dev/null | awk '{print $1}' | sort -u | tr '\n' ' ')"
done

printf '\n----- EGRESS IP -----\n'
curl -s --max-time 10 https://api.ipify.org; echo
