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
1ICANN 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
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.
curljq(>= 1.6)
Both are available in standard package repositories on all major Linux distributions and macOS (via Homebrew).
curl -sL https://gist.githubusercontent.com/TorstenC/2c2e2676629c6a601711f0450552a3f0/raw/rdap-domain-events.sh \
-o ~/.local/bin/whois2
chmod +x ~/.local/bin/whois2whois2 <domain>Exit code 0 on success, 1 on RDAP error (domain not found, registry unavailable, etc.).
has("errorCode") for error detection
if jq -e 'has("errorCode")' <<< "$json" >/dev/null 2>&1; thenUsing 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.
MIT