dns

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLocalDNSDisabled = errors.New("local dns is disabled")
)

Functions

func LookupIP4 added in v0.12.1

func LookupIP4(host string) (ips []net.IP, err error)

func LookupIP6 added in v0.12.1

func LookupIP6(host string) (ips []net.IP, err error)

Types

type LocalDNS added in v0.10.3

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

LocalDNS local dns server it has a simple dns cache, and can customize dns message exchange function

func NewLocalDNS added in v0.10.3

func NewLocalDNS(opts Options) *LocalDNS

func (*LocalDNS) LookupIP added in v0.10.3

func (s *LocalDNS) LookupIP(host string,
	exchange func(dnServer string, query *dns.Msg) (resp *dns.Msg, err error)) (ips []net.IP, err error)

LookupIP lookup ip address for a host use custom exchange function

func (*LocalDNS) ReverseLookup added in v0.10.3

func (s *LocalDNS) ReverseLookup(ip string) (hosts []string, err error)

ReverseLookup reverse lookup hostnames for an ip address

func (*LocalDNS) Run added in v0.10.3

func (s *LocalDNS) Run()

Run run the local dns server

type Options

type Options struct {
	Listen   string                                                                              // listen address
	Upstream string                                                                              // upstream dns server
	Evict    time.Duration                                                                       // cache evict duration
	Exchange func(upstream string, clientAddr string, query *dns.Msg) (resp *dns.Msg, err error) // dns message exchange function
}

Options local dns server options

type Resolver added in v0.12.1

type Resolver struct {
	IPv4Servers []string
	IPv6Servers []string
	Exchange    func(dnServer string, r *dns.Msg) (*dns.Msg, error)
}
var DefaultResolver Resolver = Resolver{
	IPv4Servers: []string{"8.8.8.8:53", "223.5.5.5:53"},
	IPv6Servers: []string{"[2001:4860:4860::8888]:53", "[2400:3200::1]:53"},
	Exchange: func(dnServer string, r *dns.Msg) (resp *dns.Msg, err error) {
		dnsLookupCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
		defer cancel()
		resp, _, err = dnsClient.ExchangeContext(dnsLookupCtx, r, dnServer)
		return
	},
}

func (*Resolver) LookupIP added in v0.12.1

func (r *Resolver) LookupIP(host string, t uint16) (ips []net.IP, err error)

Jump to

Keyboard shortcuts

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