Back to cheatsheets
Privacy
DNS-over-HTTPS Queries
Query DNS records with encrypted DoH lookups and DNSSEC validation.
What you'll learn
- DoH lookup
- Multi-resolver with fallback
- Record types reference
How to use these snippets
- Click the Copy button next to any snippet to copy it to your clipboard.
- Paste the code into your project, IDE, or terminal.
- Replace placeholder values (like
example.comoryour-secret) with your actual data. - Review the code comments for important security notes and caveats.
- Try the interactive related tool to see the concept in action.
Code Snippets
Copy-paste code snippets
3 ready-to-use snippets for dns-over-https queries. Click copy and paste into your project.
DoH lookup
async function dohLookup(domain, type = 'A') {
const url = `https://cloudflare-dns.com/dns-query?name=${domain}&type=${type}`;
const res = await fetch(url, {
headers: { 'Accept': 'application/dns-json' }
});
const json = await res.json();
return json.Answer || [];
}
Multi-resolver with fallback
const RESOLVERS = [
'https://cloudflare-dns.com/dns-query',
'https://dns.quad9.net:5053/dns-query',
'https://dns.google/resolve',
];
async function dohWithFallback(domain, type = 'A') {
for (const resolver of RESOLVERS) {
try {
const url = `${resolver}?name=${domain}&type=${type}`;
const res = await fetch(url, {
headers: { 'Accept': 'application/dns-json' }
});
const json = await res.json();
if (json.Answer) return json.Answer;
} catch (e) { continue; }
}
throw new Error('All resolvers failed');
}
Record types reference
// Common DNS record types:
// A — IPv4 address
// AAAA — IPv6 address
// CNAME — Canonical name (alias)
// MX — Mail exchange
// TXT — Text (SPF, DKIM, verification)
// NS — Name server
// SOA — Start of authority
// CAA — Certificate Authority Authorization
// SRV — Service record
// PTR — Reverse lookup (IP → domain)
// DS — Delegation signer (DNSSEC)
Tool
Related ShieldX tool
Try this concept hands-on with the interactive tool.
100% Free · No signup · No cost
Generate something unguessable right now
148 bits of entropy, a crack-time estimate you can trust, and a clipboard that clears itself after 30 seconds.
Part of the Toolly ecosystem · secure.toolly.site