Skip to content

Instantly share code, notes, and snippets.

@mw866
Last active December 27, 2021 06:49
Show Gist options
  • Select an option

  • Save mw866/6100d6ea01d533d2ea1ea25b5d9c0941 to your computer and use it in GitHub Desktop.

Select an option

Save mw866/6100d6ea01d533d2ea1ea25b5d9c0941 to your computer and use it in GitHub Desktop.
#doh #dns
# The DNS-over-HTTPS wrapper over curl. It supports JSON format instead of wire format (RFC 8484)
# For best results, add it to your shell startup config files .e.g. .zshrc, .bashrc, or .bash_profile
# Some usage examples:
# doh www.example.com
# doh www.example.com AAAA
# doh www.example.com AAAA https://cloudflare-dns.com/dns-query
doh() {
if [ "$1" = "" ]|| [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Usage: doh name [rrtype] [doh_url]"
echo "Default:"
echo " rrtype: A"
echo " doh_url: https://cloudflare-dns.com/dns-query"
return 0
fi
if [ "$2" = "" ]; then
rrtype="&type=A"
else
rrtype="&type=$2"
fi
if [ "$3" = "" ]; then
url="https://cloudflare-dns.com/dns-query"
else
url=$3
fi
curl -s -H "accept: application/dns-json" "$url?name=$1$rrtype" | jq
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment