dnsclient

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2023 License: GPL-2.0 Imports: 14 Imported by: 9

README

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

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDialer added in v0.2.0

func GetDialer(socksURL string) (proxy.Dialer, error)

Types

type ClassicDNS

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

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

func (*ClassicDNS) Close

func (c *ClassicDNS) Close() error

Close closes the DNS Client

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

func (*ClassicDNS) Reconnect added in v0.2.0

func (c *ClassicDNS) Reconnect() error

Reconnect reads the configuration from the running instance, and tries to replace the client with a fresh connection on-the-fly

type Client

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

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)
}

func New

func New(uri string, skipVerify bool, proxy string) (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, proxy string) (Client, error)

NewClassicDNS provides a client interface which you can query on

func NewDoHClient

func NewDoHClient(server url.URL, SkipVerify bool, proxy string) (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

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

DoHClient encapsulates all functions and attributes for a DoH client

func (*DoHClient) Close

func (c *DoHClient) Close() error

func (DoHClient) Query

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

Query performs a DoH query

func (*DoHClient) Reconnect added in v0.2.0

func (c *DoHClient) Reconnect() error

type DoQClient

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

DoQClient encapsulates all functions and attributes for a DoH client

func (*DoQClient) Close

func (c *DoQClient) Close() error

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

func (*DoQClient) Reconnect added in v0.2.0

func (c *DoQClient) Reconnect() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL