Giter VIP home page Giter VIP logo

dns-over-http-resolver's Introduction

dns-over-http-resolver

Build Status dependencies Status JavaScript Style Guide Downloads Minzipped size codecov GitHub Workflow Status

DNS over HTTP resolver

Isomorphic DNS over HTTP resolver using fetch.

API based on Node.js' dns promises API, allowing the native dns module to be used if available when relying on this API.

Install

npm i dns-over-http-resolver

Usage

const DnsOverHttpResolver = require('dns-over-http-resolver')

const dohResolver = new DnsOverHttpResolver(options)

Cloudflare and Google DNS servers are used by default. They can be replaced via the API.

You can also use require('dns').promises in Node.js in lieu of this module.

options

You can provide the following options for the DnsOverHttpResolver:

Name Type Description Default
maxCache number maximum number of cached dns records 100

API

resolve(hostname, rrType)

Uses the DNS protocol to resolve the given host name into a DNS record.

Parameters

Name Type Description
hostname string host name to resolve
[rrType] string resource record type (default: 'A')

Returns

Type Description
Promise<Array<string>> returns a Promise resolving a DNS record according to its type

Example

const DnsOverHttpResolver = require('dns-over-http-resolver')
const resolver = new DnsOverHttpResolver()

const hostname = 'google.com'
const recordType = 'TXT'

const dnsRecord = await resolver.resolve(hostname, recordType)

resolve4(hostname)

Uses the DNS protocol to resolve the given host name into IPv4 addresses.

Parameters

Name Type Description
hostname string host name to resolve

Returns

Type Description
Promise<Array<string>> returns a Promise resolving IPv4 addresses

Example

const DnsOverHttpResolver = require('dns-over-http-resolver')
const resolver = new DnsOverHttpResolver()

const hostname = 'google.com'

const address = await resolver.resolve4(hostname) // ['216.58.212.142']

resolve6(hostname)

Uses the DNS protocol to resolve the given host name into IPv6 addresses.

Parameters

Name Type Description
hostname string host name to resolve

Returns

Type Description
Promise<Array<string>> returns a Promise resolving IPv6 addresses

Example

const DnsOverHttpResolver = require('dns-over-http-resolver')
const resolver = new DnsOverHttpResolver()

const hostname = 'google.com'

const address = await resolver.resolve6(hostname) // ['2a00:1450:4001:801::200e']

resolveTxt(hostname)

Uses the DNS protocol to resolve the given host name into a Text Record.

Parameters

Name Type Description
hostname string host name to resolve

Returns

Type Description
Promise<Array<Array<string>>> returns a Promise resolving a Text Record

Example

const DnsOverHttpResolver = require('dns-over-http-resolver')
const resolver = new DnsOverHttpResolver()

const hostname = 'google.com'

const address = await resolver.resolveTxt(hostname) // [['v=spf1 -all']]

getServers()

Get an array of the IP addresses currently configured for DNS resolution. These addresses are formatted according to RFC 5952. It can include a custom port.

Returns

Type Description
Array<string> returns array of DNS servers used

Example

const DnsOverHttpResolver = require('dns-over-http-resolver')

const resolver = new DnsOverHttpResolver()
const servers = resolver.getServers()

setServers(servers)

Sets the IP address and port of servers to be used when performing DNS resolution. Note that the servers order will be randomized on each request for load distribution.

Parameters

Name Type Description
servers Array<string> Array of RFC 5952 formatted addresses.

Example

const DnsOverHttpResolver = require('dns-over-http-resolver')

const resolver = new DnsOverHttpResolver()
resolver.setServers(['https://cloudflare-dns.com/dns-query'])

Contribute

Feel free to dive in! Open an issue or submit PRs.

License

MIT © Vasco Santos

dns-over-http-resolver's People

Contributors

vasco-santos avatar dependabot-preview[bot] avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.