Skip to content

Commit

Permalink
http-dns-round-robin.sh: fix round-robin
Browse files Browse the repository at this point in the history
An attempt to remove CNAMEs removed IP addresses, too.
  • Loading branch information
oh2fih committed Sep 27, 2024
1 parent 8c24aa6 commit 876fbc2
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions bin/http-dns-round-robin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ required_command "dig" "for DNS queries"
required_command "head"
required_command "tail"
required_command "awk"
required_command "grep"

if [ "$UNMET" -gt 0 ]; then
exit 1
Expand All @@ -39,13 +40,32 @@ if ! [[ $URL =~ $regex ]]; then
exit 1
fi

IPV4SEG="(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
IPV4ADDR="(${IPV4SEG}\.){3,3}${IPV4SEG}"
IPV6SEG="[0-9a-fA-F]{1,4}"
IPV6ADDR="("
IPV6ADDR+="(${IPV6SEG}:){7,7}${IPV6SEG}|"
IPV6ADDR+="(${IPV6SEG}:){1,7}:|"
IPV6ADDR+="(${IPV6SEG}:){1,6}:${IPV6SEG}|"
IPV6ADDR+="(${IPV6SEG}:){1,5}(:${IPV6SEG}){1,2}|"
IPV6ADDR+="(${IPV6SEG}:){1,4}(:${IPV6SEG}){1,3}|"
IPV6ADDR+="(${IPV6SEG}:){1,3}(:${IPV6SEG}){1,4}|"
IPV6ADDR+="(${IPV6SEG}:){1,2}(:${IPV6SEG}){1,5}|"
IPV6ADDR+="${IPV6SEG}:((:${IPV6SEG}){1,6})|"
IPV6ADDR+=":((:${IPV6SEG}){1,7}|:)|"
IPV6ADDR+="fe80:(:${IPV6SEG}){0,4}%[0-9a-zA-Z]{1,}|"
IPV6ADDR+="::(ffff(:0{1,4}){0,1}:){0,1}${IPV4ADDR}|"
IPV6ADDR+="(${IPV6SEG}:){1,4}:${IPV4ADDR}"
IPV6ADDR+=")"
IPADDR="${IPV4ADDR}|${IPV6ADDR}"

HOSTNAME=$(echo "$URL" | awk -F/ '{print $3}')

while read -r ip
do
echo "[${ip}]"
curl --resolve "[${HOSTNAME}]:443:${ip}" --silent --head "$URL"
done <<< "$( \
dig +short "$HOSTNAME" A | tail -n 1 \
; dig +short "$HOSTNAME" AAAA | tail -n 1
done <<< "$(
dig +short "$HOSTNAME" A | grep -E -o "$IPADDR"
dig +short "$HOSTNAME" AAAA | grep -E -o "$IPADDR"
)"

0 comments on commit 876fbc2

Please sign in to comment.