Function signature
function getAllDnsRecordsStream(
domain: string,
options?: GetAllDnsRecordsOptions
): ReadableStream
Discover all DNS records for a domain name and stream each record as a text line in real-time as it’s discovered. This is useful for:
- Processing large result sets without waiting for all records
- Streaming results to a file or network connection
- Building live progress indicators
Parameters
Valid domain name, without subdomain or protocol. For example: example.com, not https://www.example.com
Options for DNS resolver, extra subdomains to check, etc.Which DNS resolver to use for DNS lookup. Options:
cloudflare-dns
google-dns
node-dns
node-dig
deno-dns
options.commonSubdomainsCheck
Check for common subdomains from the built-in list.
List of extra subdomains to check for.
Returns
A ReadableStream of DNS records. Each chunk in the stream is a Uint8Array containing a tab-separated DNS record line in the format:name\tttl\tIN\ttype\tdata
For example:example.com\t3600\tIN\tA\t93.184.216.34
Each record in the stream is formatted as a tab-separated line with five fields:
- name - Fully qualified domain name
- ttl - Time to live in seconds
- IN - Internet class (always “IN”)
- type - Record type (A, AAAA, CNAME, MX, etc.)
- data - Record data
Examples
Read stream and collect all records
import { getAllDnsRecordsStream } from '@layered/dns-records'
const stream = getAllDnsRecordsStream('example.com')
const reader = stream.getReader()
const records = []
while (true) {
const { done, value } = await reader.read()
if (done) break
const recordLine = new TextDecoder().decode(value)
records.push(recordLine)
}
console.log(`Found ${records.length} DNS records`)
Stream records to console in real-time
import { getAllDnsRecordsStream, parseDnsRecord } from '@layered/dns-records'
const stream = getAllDnsRecordsStream('example.com', {
resolver: 'cloudflare-dns',
})
const reader = stream.getReader()
while (true) {
const { done, value } = await reader.read()
if (done) break
const record = parseDnsRecord(value)
console.log(`${record.type} ${record.name} -> ${record.data}`)
}
Process stream with async iteration
import { getAllDnsRecordsStream } from '@layered/dns-records'
const stream = getAllDnsRecordsStream('example.com', {
subdomains: ['api', 'www'],
commonSubdomainsCheck: true,
})
for await (const chunk of stream) {
const recordLine = new TextDecoder().decode(chunk)
// Process each record as it arrives
console.log(recordLine)
}
Write stream directly to a file
import { getAllDnsRecordsStream } from '@layered/dns-records'
import { createWriteStream } from 'fs'
const stream = getAllDnsRecordsStream('example.com')
const fileStream = createWriteStream('dns-records.txt')
const reader = stream.getReader()
while (true) {
const { done, value } = await reader.read()
if (done) {
fileStream.end()
break
}
fileStream.write(value)
fileStream.write('\n')
}