Skip to content

Instantly share code, notes, and snippets.

@TorstenC
Last active May 19, 2026 23:47
Show Gist options
  • Select an option

  • Save TorstenC/2c2e2676629c6a601711f0450552a3f0 to your computer and use it in GitHub Desktop.

Select an option

Save TorstenC/2c2e2676629c6a601711f0450552a3f0 to your computer and use it in GitHub Desktop.
Query RDAP registration and last-changed events for a domain using curl + jq. No registry lookup table needed — rdap.org bootstraps automatically.

rdap-domain-events.sh

A minimal Bash script to query registration and last changed dates for any domain name using the RDAP protocol — the modern, structured replacement for WHOIS.

$ whois2 google.com
registration: 1997-09-15T04:00:00Z
last changed: 2019-09-09T15:39:04Z

$ whois2 adskahsjdk.ai; echo $?
RDAP error: Object not found - Object not found
1

Why RDAP instead of WHOIS?

ICANN has officially replaced WHOIS with RDAP. The key advantages for scripting:

  • Structured JSON responses — no fragile text parsing with grep/sed
  • Consistent field names across all registries
  • Proper HTTP status codes for error handling
  • UTF-8 and internationalized domain names supported natively

Why rdap.org as the endpoint?

Traditional WHOIS requires knowing which registry serves a given TLD. rdap.org acts as a bootstrap resolver: it looks up the correct authoritative RDAP server automatically, so no lookup table is needed in the script.

Dependencies

  • curl
  • jq (>= 1.6)

Both are available in standard package repositories on all major Linux distributions and macOS (via Homebrew).

Installation

curl -sL https://gist.githubusercontent.com/TorstenC/2c2e2676629c6a601711f0450552a3f0/raw/rdap-domain-events.sh \
  -o ~/.local/bin/whois2
chmod +x ~/.local/bin/whois2

Usage

whois2 <domain>

Exit code 0 on success, 1 on RDAP error (domain not found, registry unavailable, etc.).

Notable implementation details

has("errorCode") for error detection

if jq -e 'has("errorCode")' <<< "$json" >/dev/null 2>&1; then

Using has() checks for key existence in the JSON object regardless of the value — more reliable than .errorCode?, which can silently pass when the key is present but null.

Here-string instead of echo pipe

jq -r '...' <<< "$json"

Avoids a subshell and an extra process compared to echo "$json" | jq. It's the idiomatic Bash pattern for feeding a variable into jq.

set -euo pipefail

Ensures the script exits immediately on errors, treats unset variables as errors, and propagates failures through pipelines.

License

MIT

#!/usr/bin/env bash
set -euo pipefail
domain="${1:?Usage: $0 <domain>}"
json="$(curl -sL "https://rdap.org/domain/$domain")"
# Prüfen: Fehlerobjekt vorhanden?
if jq -e 'has("errorCode")' <<< "$json" >/dev/null 2>&1; then
title=$(jq -r '.title // "Unknown error"' <<< "$json")
desc=$(jq -r '.description[0] // empty' <<< "$json")
echo "RDAP error: $title${desc:+ - $desc}"
exit 1
fi
# Events sicher extrahieren
jq -r '
(.events // [])
| map(select(.eventAction == "registration" or .eventAction == "last changed"))
| if length == 0 then
"No relevant events found"
else
.[] | "\(.eventAction): \(.eventDate)"
end
' <<< "$json"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment