package module
Version: v1.0.12 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2021 License: MIT Imports: 11 Imported by: 8


Retryable dns resolver

Based on miekg/dns and freely inspired by bogdanovich/dns_resolver.


  • Supports system default resolvers along with user supplied ones
  • Retries dns requests in case of I/O/Time/Network failures
  • Allows arbitrary query types
  • Resolution with random resolvers
Using go get
$ go get

After this command retryabledns library source will be in your $GOPATH


Usage Example:

package main

import (


func main() {
    // it requires a list of resolvers
    resolvers := []string{"", ""}
    retries := 2
    hostname := ""
    dnsClient := retryabledns.New(resolvers, retries)

    ips, err := dnsClient.Resolve(hostname)
    if err != nil {


    // Query Types: dns.TypeA, dns.TypeNS, dns.TypeCNAME, dns.TypeSOA, dns.TypePTR, dns.TypeMX
    // dns.TypeTXT, dns.TypeAAAA (from
    dnsResponses, err := dnsClient.Query(hostname, dns.TypeA)
    if err != nil {






This section is empty.


View Source
var RootDNSServers = []RootDNS{
	{"", "", "2001:503:ba3e::2:30", "Verisign, Inc"},
	{"", "", "2001:500:200::b", "University of Southern California, Information Sciences Institute"},
	{"", "", "2001:500:2::c", "Cogent Communications"},
	{"", "", "2001:500:2d::d", "University of Maryland"},
	{"", "", "2001:500:a8::e", "NASA (Ames Research Center)"},
	{"", "", "2001:500:2f::f", "Internet Systems Consortium, Inc."},
	{"", "", "2001:500:12::d0d", "US Department of Defense (NIC)"},
	{"", "", "2001:500:1::53", "US Army (Research Lab)"},
	{"", "", "2001:7fe::53", "Netnod"},
	{"", "", "2001:503:c27::2:30", "Verisign, Inc"},
	{"", "", "2001:7fd::1", "RIPE NCC"},
	{"", "", "2001:500:9f::42", "ICANN"},
	{"", "", "2001:dc3::35", "WIDE Project"},
View Source
var RootDNSServersIPv4 = []string{
	"", "", "", "",
	"", "", "", "",
	"", "", "", "",


This section is empty.


type Client

type Client struct {
	TCPFallback bool
	Timeout     time.Duration
	// contains filtered or unexported fields

Client is a DNS resolver client to resolve hostnames.

func New

func New(baseResolvers []string, maxRetries int) *Client

New creates a new dns client

func (*Client) A

func (c *Client) A(host string) (*DNSData, error)

A helper function

func (*Client) AAAA

func (c *Client) AAAA(host string) (*DNSData, error)

AAAA helper function

func (*Client) CNAME

func (c *Client) CNAME(host string) (*DNSData, error)

CNAME helper function

func (*Client) Do

func (c *Client) Do(msg *dns.Msg) (*dns.Msg, error)

Do sends a provided dns request and return the raw native response

func (*Client) MX

func (c *Client) MX(host string) (*DNSData, error)

MX helper function

func (*Client) NS

func (c *Client) NS(host string) (*DNSData, error)

NS helper function

func (*Client) PTR

func (c *Client) PTR(host string) (*DNSData, error)

PTR helper function

func (*Client) Query

func (c *Client) Query(host string, requestType uint16) (*DNSData, error)

Query sends a provided dns request and return enriched response

func (*Client) QueryMultiple

func (c *Client) QueryMultiple(host string, requestTypes []uint16) (*DNSData, error)

QueryMultiple sends a provided dns request and return the data

func (*Client) QueryParallel

func (c *Client) QueryParallel(host string, requestType uint16, resolvers []string) ([]*DNSData, error)

QueryParallel sends a provided dns request to multiple resolvers in parallel

func (*Client) Resolve

func (c *Client) Resolve(host string) (*DNSData, error)

Resolve is the underlying resolve function that actually resolves a host and gets the ip records for that host.

func (*Client) ResolveWithSyscall

func (c *Client) ResolveWithSyscall(host string) (*DNSData, error)

ResolveWithSyscall attempts to resolve the host through system calls

func (*Client) SOA

func (c *Client) SOA(host string) (*DNSData, error)

SOA helper function

func (*Client) TXT

func (c *Client) TXT(host string) (*DNSData, error)

TXT helper function

func (*Client) Trace

func (c *Client) Trace(host string, requestType uint16, maxrecursion int) (*TraceData, error)

QueryMultiple sends a provided dns request and return the data

type DNSData

type DNSData struct {
	Host          string     `json:"host,omitempty"`
	TTL           int        `json:"ttl,omitempty"`
	Resolver      []string   `json:"resolver,omitempty"`
	A             []string   `json:"a,omitempty"`
	AAAA          []string   `json:"aaaa,omitempty"`
	CNAME         []string   `json:"cname,omitempty"`
	MX            []string   `json:"mx,omitempty"`
	PTR           []string   `json:"ptr,omitempty"`
	SOA           []string   `json:"soa,omitempty"`
	NS            []string   `json:"ns,omitempty"`
	TXT           []string   `json:"txt,omitempty"`
	Raw           string     `json:"raw,omitempty"`
	StatusCode    string     `json:"status_code,omitempty"`
	StatusCodeRaw int        `json:"status_code_raw,omitempty"`
	TraceData     *TraceData `json:"trace,omitempty"`
	RawResp       *dns.Msg   `json:"raw_resp,omitempty"`
	Timestamp     time.Time  `json:"timestamp,omitempty"`

DNSData is the data for a DNS request response

func (*DNSData) JSON

func (d *DNSData) JSON() (string, error)

JSON returns the object as json string

func (*DNSData) Marshal

func (d *DNSData) Marshal() ([]byte, error)

Marshal encodes the dnsdata to a binary representation

func (*DNSData) ParseFromMsg

func (d *DNSData) ParseFromMsg(msg *dns.Msg) error

ParseFromMsg and enrich data

func (*DNSData) Unmarshal

func (d *DNSData) Unmarshal(b []byte) error

Unmarshal decodes the dnsdata from a binary representation

type RootDNS

type RootDNS struct {
	Host     string
	IPv4     string
	IPv6     string
	Operator string

type TraceData

type TraceData struct {
	Host    string     `json:"host,omitempty"`
	DNSData []*DNSData `json:"chain,omitempty"`

TraceData contains the trace information for a dns query

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to