Skip to content

Commit

Permalink
Add http-dns-round-robin.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
oh2fih committed Sep 26, 2024
1 parent 3ecdf6d commit 8c24aa6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Miscellaneous scripts for different purposes. Mostly unrelated to each other.
| Infosec<br>Automation | [`make-mac-prefixes.py`](bin/make-mac-prefixes.py)<br>Python 3.6+ | Processes registered MAC address prefixes from [IEEE MA-L Assignments (CSV)](https://standards.ieee.org/products-programs/regauth/) (stdin) to Nmap's [`nmap-mac-prefixes`](https://github.com/nmap/nmap/blob/master/nmap-mac-prefixes) (stdout) with a few additional unregistered OUIs.<br>`curl https://standards-oui.ieee.org/oui/oui.csv \| make-mac-prefixes.py > nmap-mac-prefixes` |
| WordPress | [`test-cache-enabler.py`](bin/test-cache-enabler.py)<br>Python 3.6+ | Tests whether the Cache Enabler by KeyCDN (WordPress) is working properly on the URLs given as arguments.<br>`test-cache-enabler.py https://example.com [...]` |
| Web | [`detect-modified-html-element.sh`](bin/detect-modified-html-element.sh)<br>Shell (bash) | Checks HTML element changes on a web page since last run. Configured via environment variables.<br>Recommended to be executed as a SystemD [service](systemd/detect-modified-html-element.service.example). |
| Web | [`http-dns-round-robin.sh`](bin/http-dns-round-robin.sh)<br>Shell (bash) | Print HTTP headers for every DNS round-robin IP (IPv4 + IPv6)<br>`http-dns-round-robin.sh URL`|
| Web | [`product-pricelimiter.sh`](bin/product-pricelimiter.sh)<br>Shell (bash) | Compare product price on a web page with a given maximum price. Use, e.g., developer tools on your browser to find the HTML element containing the price.<br>`product-pricelimiter.sh -u URL -s Selector [-m MaxPrice] [-n N] [-d N]` |
| Web | <del>`koronarokotusaika.sh`</del><br>Shell (bash) | This script has been removed as koronarokotusaika.fi (bookcovidvaccine.fi) has been shut down on April 28, 2023. |
| Web | <del>`xxl-product-pricelimiter.sh`</del><br>Shell (bash) | This script has been replaced by the generalized [`product-pricelimiter.sh`](bin/product-pricelimiter.sh) as the HTML structure of XXL.fi has changed. |
Expand Down
51 changes: 51 additions & 0 deletions bin/http-dns-round-robin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash
# ------------------------------------------------------------------------------
# Print HTTP headers for every DNS round-robin IP (IPv4 + IPv6)
#
# Usage: http-dns-round-robin.sh URL
#
# Author : Esa Jokinen (oh2fih)
# Home : https://github.com/oh2fih/Misc-Scripts
# ------------------------------------------------------------------------------

URL="$1"

required_command() {
if ! command -v "$1" &> /dev/null; then
if [ -z ${2+x} ]; then
echo "This script requires ${1}!" >&2
else
echo "This script requires ${1} ${2}!" >&2
fi
((UNMET=UNMET+1))
fi
}

UNMET=0

required_command "curl" "for HTTP connections"
required_command "dig" "for DNS queries"
required_command "head"
required_command "tail"
required_command "awk"

if [ "$UNMET" -gt 0 ]; then
exit 1
fi

regex='http(s)?://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
if ! [[ $URL =~ $regex ]]; then
echo "The first argument was not a valid URL!" >&2
exit 1
fi

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
)"

0 comments on commit 8c24aa6

Please sign in to comment.