2.1.0 • Published 1 year ago

@layered/dns-records v2.1.0

Weekly downloads
26
License
MIT
Repository
github
Last release
1 year ago

šŸŒ DNS Records

@layered/dns-records is a DNS helper library than can quickly discover and retrieve all DNS records for a domain.

  • Retrieves DNS records for a domain
  • Discovers (almost) all A, AAAA, CNAME, and TXT for a domain
  • Detects wildcard * records
  • Option to specify extra subdomains to check for
  • Provides results in common format, see DnsRecord
  • Works in all JavaScript runtimes: Browsers, Node.js, CloudFlare Workers, Deno, Bun, etc

→ See it in action here https://dmns.app

Getting Started

Installation

npm i @layered/dns-records

Usage

The library has a simple API. Use getAllDnsRecords(domain) to retrieve all DNS records for a domain OR request specific record types with getDnsRecords(hostname, 'TXT')

Example

import { getDnsRecords, getAllDnsRecords } from '@layered/dns-records'

const txtRecords = await getDnsRecords('google.com', 'TXT')
const allRecords = await getAllDnsRecords('x.com')

DNS Resolvers

Here is the list of supported DNS resolvers:

NameJS RuntimeNotes
cloudflare-dnsWorks on allRequires fetch as global
google-dnsWorks on allRequires fetch as global
node-dnsWorks only in Node.jsUses Node.js DNS module
node-digWorks only in Node.jsUses dig command
deno-dnsWorks only in DenoUses Deno.resolveDns

Client API

DNS Records by type

getDnsRecords(name: string, type: string = 'A', resolver?): Promise<DnsRecord[]>

Paramstypedefaultdescription
namestringhostname. Ex: 'x.com' or email.apple.com
typestringArecord type: Ex: 'TXT', 'MX', 'CNAME'
resolverstringDNS resolver to use, see resolvers above. If not set, the best match for current runtime will be used
import { getDnsRecords } from '@layered/dns-records'

const records1 = await getDnsRecords('google.com', 'A')
console.log('DNS A records', records1)

const records2 = await getDnsRecords('google.com', 'TXT')
console.log('DNS TXT records', records2)

Returns a promise which resolves with an DnsRecord[] of records found:

[ { name: 'google.com.',
    ttl: 608,
    type: 'TXT',
    data: '"v=spf1 include:_spf.google.com ~all"' },
  ...
]

All DNS records

getAllDnsRecords(domain: string, options: GetAllDnsRecordsOptions): Promise<DnsRecord[]>

Paramstypedescription
domainstringValid domain name, ex: 'google.com'
optionsobjectsee GetAllDnsRecordsOptions
import { getAllDnsRecords } from '@layered/dns-records'

const allRecords = await getAllDnsRecords('x.com', {
  resolver: 'cloudflare-dns',
  commonSubdomainsCheck: true,
})
console.log('DNS all records', allRecords)

Returns a Promise which resolves with DnsRecord[] of all records found:

[ { name: 'x.com.', ttl: 3600, type: 'NS', data: 'ns71.domaincontrol.com.' },
  { name: 'x.com.', ttl: 3600, type: 'NS', data: 'ns72.domaincontrol.com.' },
  { name: 'x.com.', ttl: 600, type: 'SOA', data: 'ns71.domaincontrol.com. dns.jomax.net. 2018071100 28800 7200 604800 600' },
  { name: 'x.com.', ttl: 600, type: 'A', data: '160.153.63.10' },
  { name: 'x.com.', ttl: 600, type: 'A', data: '160.153.63.10' },
  { name: 'www.x.com.',  ttl: 3600, type: 'CNAME', data: 'x.com.' },
  { name: 'x.com.', ttl: 3600, type: 'MX', data: '10 mx-van.mail.am0.yahoodns.net.' }
]

More

Please report any issues here on GitHub. Any contributions are welcome

License

MIT

Copyright (c) Andrei Igna, Layered

2.1.0

1 year ago

2.0.0

1 year ago

2.0.0-beta.10

1 year ago

2.0.0-beta.9

1 year ago

2.0.0-beta.8

1 year ago

2.0.0-beta.7

1 year ago

2.0.0-beta.6

1 year ago

2.0.0-beta.5

1 year ago

2.0.0-beta.4

1 year ago

2.0.0-beta.2

2 years ago

2.0.0-beta.1

2 years ago

2.0.0-beta.3

2 years ago

1.5.0

4 years ago

1.4.3

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago