dnsclient

import "github.com/mosajjal/dnsclient"

Package dnsclient provides a minimal DNS client library. It provides native support for – Dns Over UDP – DNS Over TCP – DNS Over HTTPS (DoH) – DNS Over TLS (DoT) – DNS Over QUIC (DoQ)

Index

type ClassicDNS

ClassicDNS provides functionality to create DNS over UDP, DNS over TCP and DNS over TLS

type ClassicDNS struct {
    // contains filtered or unexported fields
}

func (ClassicDNS) Query

func (c ClassicDNS) Query(ctx context.Context, q *dns.Msg) (responses []dns.RR, rtt time.Duration, err error)

Query takes a dns message and returns a list of resources

type Client

Client Provides a unified interface for DNS queries

func main() {
	msg := dns.Msg{}
	msg.RecursionDesired = true
	msg.Question = []dns.Question{{
		Name:   "example.com.",
		Qtype:  dns.StringToType["A"],
		Qclass: dns.ClassINET,
	}}

	addr := &net.UDPAddr{
		IP:   net.IPv4(1, 1, 1, 1),
		Port: 53,
	}
	c, _ := dnsclient.NewClassicDNS(addr, false, false, false)
	response, ttr, err := c.Query(context.Background(), &msg)
	fmt.Printf("Query: %v, Response: %v, Time to Respond: %s, Error: %v", msg, response, ttr, err)
}

type Client interface {
    Query(context.Context, *dns.Msg) ([]dns.RR, time.Duration, error)
}

func New

func New(uri string, skipVerify bool) (Client, error)

New creates a DNS Client by parsing a URI and returning the appropriate client for it URI string could look like below:

- udp://1.1.1.1:53
- udp6://[2606:4700:4700::1111]:53
- tcp://9.9.9.9:5353
- https://dns.adguard.com
- quic://dns.adguard.com:8853
- tls://dns.adguard.com:853

func NewClassicDNS

func NewClassicDNS(server net.Addr, UseTCP bool, UseTLS bool, SkipVerify bool) (Client, error)

NewClassicDNS provides a client interface which you can query on

func NewDoHClient

func NewDoHClient(server url.URL, SkipVerify bool) (Client, error)

NewDoHClient creates a new DoH client

func NewDoQClient

func NewDoQClient(server string, SkipVerify bool) (Client, error)

NewDoQClient creates a new DoQ client

type DoHClient

DoHClient encapsulates all functions and attributes for a DoH client

type DoHClient struct {
    Session httptrace.ClientTrace
    URL     url.URL
    // contains filtered or unexported fields
}

func (DoHClient) Query

func (c DoHClient) Query(ctx context.Context, msg *dns.Msg) ([]dns.RR, time.Duration, error)

Query performs a DoH query

type DoQClient

DoQClient encapsulates all functions and attributes for a DoH client

type DoQClient struct {
    // contains filtered or unexported fields
}

func (DoQClient) Query

func (c DoQClient) Query(ctx context.Context, msg *dns.Msg) (responses []dns.RR, rtt time.Duration, err error)

Query performs the DNS transaction

Generated by gomarkdoc

GitHub

View Github