Skip to content

Commit

Permalink
http-dns-round-robin.sh: support port in url
Browse files Browse the repository at this point in the history
Support https://example.com:443/ URLs.
Default to 443 with https:, otherwise to 80.
  • Loading branch information
oh2fih committed Sep 28, 2024
1 parent 876fbc2 commit 48732e1
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions bin/http-dns-round-robin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,24 @@ IPV6ADDR+="(${IPV6SEG}:){1,4}:${IPV4ADDR}"
IPV6ADDR+=")"
IPADDR="${IPV4ADDR}|${IPV6ADDR}"

HOSTNAME=$(echo "$URL" | awk -F/ '{print $3}')
PROTOCOL=$(echo "$URL" | awk -F/ '{print $1}')
HOSTPORT=$(echo "$URL" | awk -F/ '{print $3}')
if [[ $HOSTPORT =~ .*:[0-9]+ ]]; then
PORT="$(echo "$HOSTPORT" | awk -F: '{print $NF}')"
HOSTNAME="${HOSTPORT%":${PORT}"}"
else
HOSTNAME="$HOSTPORT"
if [[ $PROTOCOL == 'https:' ]]; then
PORT=443
else
PORT=80
fi
fi

while read -r ip
do
echo "[${ip}]"
curl --resolve "[${HOSTNAME}]:443:${ip}" --silent --head "$URL"
echo "[${ip}]:${PORT}"
curl --resolve "[${HOSTNAME}]:${PORT}:${ip}" --silent --head "$URL"
done <<< "$(
dig +short "$HOSTNAME" A | grep -E -o "$IPADDR"
dig +short "$HOSTNAME" AAAA | grep -E -o "$IPADDR"
Expand Down

0 comments on commit 48732e1

Please sign in to comment.