Documentation
¶
Overview ¶
Package resolver provides DNS lookup functions
Index ¶
- func AsServerAddress(server string) (string, error)
- func Decanonize(qname string) string
- func ForEachAnswer[T dns.RR](msg *dns.Msg, fn func(v T))
- func GetFirstAnswer[T dns.RR](msg *dns.Msg) T
- func HasAnswerType(msg *dns.Msg, qType uint16) bool
- func HasNsType(msg *dns.Msg, qType uint16) bool
- func SystemResolver(preferGo bool) *net.Resolver
- func SystemResolverWithDialer(preferGo bool, dialer DialerFunc) *net.Resolver
- type DialerFunc
- type Exchanger
- type ExchangerFunc
- type LookupResolver
- func (LookupResolver) LookupAddr(_ context.Context, name string) ([]string, error)
- func (r LookupResolver) LookupCNAME(ctx context.Context, host string) (string, error)
- func (LookupResolver) LookupHost(_ context.Context, name string) (addrs []string, err error)
- func (r LookupResolver) LookupIP(ctx context.Context, network, host string) (s []net.IP, err error)
- func (r LookupResolver) LookupIPAddr(ctx context.Context, host string) ([]net.IPAddr, error)
- func (r LookupResolver) LookupMX(ctx context.Context, name string) ([]*net.MX, error)
- func (LookupResolver) LookupNS(_ context.Context, name string) ([]*net.NS, error)
- func (r LookupResolver) LookupNetIP(ctx context.Context, network, host string) ([]netip.Addr, error)
- func (r LookupResolver) LookupSRV(ctx context.Context, service, proto, name string) (string, []*net.SRV, error)
- func (r LookupResolver) LookupTXT(ctx context.Context, name string) ([]string, error)
- type Lookuper
- type LookuperFunc
- type MultiLookuper
- type Resolver
- type RootLookuper
- func (r RootLookuper) Exchange(ctx context.Context, m *dns.Msg) (*dns.Msg, error)
- func (r RootLookuper) Iterate(ctx context.Context, name string, qtype uint16, startAt string) (*dns.Msg, error)
- func (r RootLookuper) IterateMsg(ctx context.Context, req *dns.Msg, startAt string) (*dns.Msg, error)
- func (r RootLookuper) Lookup(ctx context.Context, qName string, qType uint16) (*dns.Msg, error)
- type SingleLookuper
- func NewCloudflareLookuper() *SingleLookuper
- func NewGoogleLookuper() *SingleLookuper
- func NewGoogleLookuper2() *SingleLookuper
- func NewQuad9Lookuper() *SingleLookuper
- func NewQuad9Lookuper6() *SingleLookuper
- func NewSingleLookuper(server string, recursive bool) (*SingleLookuper, error)
- func NewSingleLookuperWithClient(server string, recursive bool, c client.Client) (*SingleLookuper, error)
- type ZeroLookuper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsServerAddress ¶ added in v0.2.0
AsServerAddress validates and optionally appends :53 port if it wasn't specified already
func Decanonize ¶ added in v0.4.5
Decanonize removes the trailing . if present, unless it's the root dot
func ForEachAnswer ¶ added in v0.1.3
ForEachAnswer calls a function for each answer of the specified type.
func GetFirstAnswer ¶ added in v0.7.1
GetFirstAnswer returns the first answer for a specified type
func HasAnswerType ¶ added in v0.7.7
HasAnswerType checks if a dns.Msg contains answers of the specified type.
func HasNsType ¶ added in v0.7.7
HasNsType checks if a dns.Msg contains Ns entries of the specified type
func SystemResolver ¶ added in v0.0.3
SystemResolver returns a standard net.Resolver configured to preferGo or not
func SystemResolverWithDialer ¶ added in v0.0.3
func SystemResolverWithDialer(preferGo bool, dialer DialerFunc) *net.Resolver
SystemResolverWithDialer returns a standard net.Resolver configured to preferGo or not and use the given Dialer instead of the default
Types ¶
type DialerFunc ¶ added in v0.0.3
A DialerFunc is a function that establishes TCP or UDP connection
type Exchanger ¶ added in v0.6.0
Exchanger performs a Lookup using a pre-assembled dns.Msg question.
type ExchangerFunc ¶ added in v0.6.2
ExchangerFunc is a function that implements the Exchanger interface
type LookupResolver ¶ added in v0.0.3
type LookupResolver struct {
// contains filtered or unexported fields
}
LookupResolver uses a Lookuper to implement the Resolver inteface
func NewResolver ¶ added in v0.0.3
func NewResolver(h Lookuper) *LookupResolver
NewResolver returns a Resolver using the provided Lookuper
func NewRootResolver ¶ added in v0.4.9
func NewRootResolver(start string) (*LookupResolver, error)
NewRootResolver creates a LookupResolver using iterative lookup from a given root-server, or random if the argument is ""
func (LookupResolver) LookupAddr ¶ added in v0.0.3
LookupAddr performs a reverse lookup for the given address, returning a list of names mapping to that address
func (LookupResolver) LookupCNAME ¶ added in v0.0.3
LookupCNAME returns the final canonical name after following zero or more CNAME records
func (LookupResolver) LookupHost ¶ added in v0.0.3
LookupHost returns a slice of the host's addresses
func (LookupResolver) LookupIP ¶ added in v0.0.3
LookupIP returns the IP addresses of a host in the form of a slice of net.IP. The network must be one of "ip", "ip4" or "ip6".
func (LookupResolver) LookupIPAddr ¶ added in v0.0.3
LookupIPAddr returns the IP addresses of a host in the form of a slice of net.IPAddr
func (LookupResolver) LookupMX ¶ added in v0.0.3
LookupMX returns the DNS MX records for the given domain name sorted by preference
func (LookupResolver) LookupNS ¶ added in v0.0.3
LookupNS returns the DNS NS records for the given domain name
func (LookupResolver) LookupNetIP ¶ added in v0.0.3
func (r LookupResolver) LookupNetIP(ctx context.Context, network, host string) ([]netip.Addr, error)
LookupNetIP looks up host using the assigned Lookuper. It returns a slice of that host's IP addresses of the type specified by network. The network must be one of "ip", "ip4" or "ip6".
type Lookuper ¶ added in v0.0.3
type Lookuper interface {
Lookup(ctx context.Context, qName string, qType uint16) (*dns.Msg, error)
}
Lookuper is the interface that wraps the basic iterative Lookup method.
type LookuperFunc ¶ added in v0.6.2
LookuperFunc is a function that implements the Lookuper interface
type MultiLookuper ¶ added in v0.2.0
type MultiLookuper struct {
// contains filtered or unexported fields
}
MultiLookuper queries multiple Lookupers in parallel and takes the first non-error answer
func NewMultiLookuper ¶ added in v0.2.0
func NewMultiLookuper(lookupers ...Lookuper) *MultiLookuper
NewMultiLookuper creates a new Multilookuper using the given Lookupers
func NewMultiLookuperAddresses ¶ added in v0.2.0
func NewMultiLookuperAddresses(servers ...string) (*MultiLookuper, error)
NewMultiLookuperAddresses creates a new Multilookuper composing SingleLookupers for each given address
type Resolver ¶ added in v0.0.3
type Resolver interface { // LookupIPAddr looks up host using the assigned Lookuper. // It returns a slice of that host's IPv4 and IPv6 addresses. LookupIPAddr(ctx context.Context, host string) ([]net.IPAddr, error) // LookupIP looks up host for the given network using assigned Lookuper // It returns a slice of that host's IP addresses of the type specified // by network. network must be one of "ip", "ip4" or "ip6". LookupIP(ctx context.Context, network, host string) ([]net.IP, error) // LookupNetIP looks up host using the assigned Lookuper. It returns a // slice of that host's IP addresses of the type specified by network. // The network must be one of "ip", "ip4" or "ip6". LookupNetIP(ctx context.Context, network, host string) ([]netip.Addr, error) // LookupAddr performs a reverse lookup for the given address, returning a list // of names mapping to that address. // // The returned names are validated to be properly formatted presentation-format // domain names. If the response contains invalid names, those records are // filtered out and an error will be returned alongside the remaining results, // if any. LookupAddr(ctx context.Context, addr string) ([]string, error) // LookupCNAME returns the canonical name for the given host. Callers that do not // care about the canonical name can call LookupHost or LookupIP directly; both // take care of resolving the canonical name as part of the lookup. // A canonical name is the final name after following zero or more CNAME records. // LookupCNAME does not return an error if host does not contain DNS "CNAME" // records, as long as host resolves to address records. // The returned canonical name is validated to be a properly formatted // presentation-format domain name. LookupCNAME(ctx context.Context, host string) (string, error) // LookupHost looks up the given host using the assigned Lookuper. It returns a // slice of that host's addresses. LookupHost(ctx context.Context, host string) (addrs []string, err error) // LookupMX returns the DNS MX records for the given domain name sorted by // preference. // The returned mail server names are validated to be properly formatted // presentation-format domain names. If the response contains invalid names, // those records are filtered out and an error will be returned alongside // the remaining results, if any. LookupMX(ctx context.Context, name string) ([]*net.MX, error) // LookupNS returns the DNS NS records for the given domain name. // The returned name server names are validated to be properly formatted // presentation-format domain names. If the response contains invalid names, // those records are filtered out and an error will be returned alongside // the remaining results, if any. LookupNS(ctx context.Context, name string) ([]*net.NS, error) // LookupSRV tries to resolve an SRV query of the given service, protocol, // and domain name. The proto is "tcp" or "udp". The returned records are // sorted by priority and randomized by weight within a priority. // // LookupSRV constructs the DNS name to look up following RFC 2782. That is, // it looks up _service._proto.name. To accommodate services publishing SRV // records under non-standard names, if both service and proto are empty // strings, LookupSRV looks up name directly. // // The returned service names are validated to be properly formatted // presentation-format domain names. If the response contains invalid names, // those records are filtered out and an error will be returned alongside // the remaining results, if any. LookupSRV(ctx context.Context, service, proto, name string) (cname string, addrs []*net.SRV, err error) // LookupTXT returns the DNS TXT records for the given domain name. LookupTXT(ctx context.Context, name string) ([]string, error) }
A Resolver implements the interface of net.Resolver
type RootLookuper ¶ added in v0.1.0
type RootLookuper struct { Start string // contains filtered or unexported fields }
RootLookuper does iterative lookup using the given root-server as starting point
func NewRootLookuper ¶ added in v0.1.1
func NewRootLookuper(start string) (*RootLookuper, error)
NewRootLookuper creates a RootLookuper using the indicated root, or random if the argument is ""
func NewRootLookuperWithClient ¶ added in v0.7.3
func NewRootLookuperWithClient(start string, c client.Client) (*RootLookuper, error)
NewRootLookuperWithClient creates a RootLookuper using the indicated root, or random if the argument is "", and uses the given client.Client to connect.
func (RootLookuper) Exchange ¶ added in v0.3.0
Exchange queries any root server and validates the response
func (RootLookuper) Iterate ¶ added in v0.3.0
func (r RootLookuper) Iterate(ctx context.Context, name string, qtype uint16, startAt string, ) (*dns.Msg, error)
Iterate is an iterative lookup implementation
type SingleLookuper ¶ added in v0.2.0
type SingleLookuper struct {
// contains filtered or unexported fields
}
SingleLookuper asks a single server for a direct answer to the query preventing repetition
func NewCloudflareLookuper ¶ added in v0.2.0
func NewCloudflareLookuper() *SingleLookuper
NewCloudflareLookuper creates a Lookuper asking 1.1.1.1 (Cloudflare)
func NewGoogleLookuper ¶ added in v0.2.0
func NewGoogleLookuper() *SingleLookuper
NewGoogleLookuper creates a Lookuper asking 8.8.8.8 (Google)
func NewGoogleLookuper2 ¶ added in v0.2.0
func NewGoogleLookuper2() *SingleLookuper
NewGoogleLookuper2 creates a Lookuper asking 8.8.4.4 (Google)
func NewQuad9Lookuper ¶ added in v0.2.0
func NewQuad9Lookuper() *SingleLookuper
NewQuad9Lookuper creates a Lookuper asking 9.9.9.9 (Quad9.net)
func NewQuad9Lookuper6 ¶ added in v0.2.0
func NewQuad9Lookuper6() *SingleLookuper
NewQuad9Lookuper6 creates a Lookuper asking Quad9.net using IPv6
func NewSingleLookuper ¶ added in v0.2.0
func NewSingleLookuper(server string, recursive bool) (*SingleLookuper, error)
NewSingleLookuper creates a Lookuper that asks one particular server
func NewSingleLookuperWithClient ¶ added in v0.7.3
func NewSingleLookuperWithClient(server string, recursive bool, c client.Client) (*SingleLookuper, error)
NewSingleLookuperWithClient creates a lookuper that asks one particular server using the provided DNS client
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
pkg
|
|
client
Package client implements DNS client wrappers
|
Package client implements DNS client wrappers |
errors
Package errors aids error handling for [dns.Msg] and darvaza.org/resolver related functions
|
Package errors aids error handling for [dns.Msg] and darvaza.org/resolver related functions |
server
Package server aids writing DNS servers
|
Package server aids writing DNS servers |