Documentation ¶
Index ¶
- Variables
- func Clean(d string) string
- func GetDomain(d string) string
- func GetDomainIndex(d string) int
- func GetSub(d string) string
- func GetTLD(d string) string
- func GetTLDIndex(d string) int
- func HasSub(d string) bool
- func IsExists(name string) (bool, error)
- func IsSetA(name string) (bool, error)
- func IsSetAAAA(name string) (bool, error)
- func IsSetCAA(name string) (bool, error)
- func IsSetCNAME(name string) (bool, error)
- func IsSetDNAME(name string) (bool, error)
- func IsSetMX(name string) (bool, error)
- func IsSetNS(name string) (bool, error)
- func IsSetSOA(name string) (bool, error)
- func IsSetSRV(name string) (bool, error)
- func IsSetTXT(name string) (bool, error)
- func IsValid(d string) booldeprecated
- func IsValidSLD(d string) booldeprecated
- func IsWildcard(name string, t uint16) (bool, error)
- func Probe(network, ip, port string, timeout time.Duration) (bool, error)
- func QueryA(name string) ([]net.IP, error)
- func QueryAAAA(name string) ([]net.IP, error)
- func QueryCNAME(name string) ([]string, error)
- func QueryDNAME(name string) (string, error)
- func QueryNS(name string) ([]string, error)
- func QueryTXT(name string) ([]string, error)
- func RcodeToError(rcode int) error
- func TryQueryA(name string) ([]net.IP, error)
- func TryQueryAAAA(name string) ([]net.IP, error)
- func TryQueryCNAME(name string) ([]string, error)
- func TryQueryDNAME(name string) (string, error)
- func TryQueryNS(name string) ([]string, error)
- func TryQueryTXT(name string) ([]string, error)
- func TypeToString(t uint16) string
- type CAA
- type MX
- type Parts
- type Record
- type SOA
- type SRV
- type Server
- func (s *Server) QueryA(name string) ([]net.IP, error)
- func (s *Server) QueryAAAA(name string) ([]net.IP, error)
- func (s *Server) QueryCAA(name string) ([]CAA, error)
- func (s *Server) QueryCNAME(name string) ([]string, error)
- func (s *Server) QueryDNAME(name string) (string, error)
- func (s *Server) QueryMX(name string) ([]MX, error)
- func (s *Server) QueryNS(name string) ([]string, error)
- func (s *Server) QuerySOA(name string) (*SOA, error)
- func (s *Server) QuerySRV(name string) ([]SRV, error)
- func (s *Server) QueryTXT(name string) ([]string, error)
- func (s *Server) Server() string
- func (s Server) String() string
- func (s *Server) ToTCP() *Server
- type Servers
- func (s *Servers) Append(srv Server)
- func (s *Servers) Get(index int) *Server
- func (s *Servers) GetMaxRetries() int
- func (s *Servers) IsSet(name string, t uint16) (bool, error)
- func (s *Servers) IsSetA(name string) (bool, error)
- func (s *Servers) IsSetAAAA(name string) (bool, error)
- func (s *Servers) IsSetCAA(name string) (bool, error)
- func (s *Servers) IsSetCNAME(name string) (bool, error)
- func (s *Servers) IsSetDNAME(name string) (bool, error)
- func (s *Servers) IsSetMX(name string) (bool, error)
- func (s *Servers) IsSetNS(name string) (bool, error)
- func (s *Servers) IsSetSOA(name string) (bool, error)
- func (s *Servers) IsSetSRV(name string) (bool, error)
- func (s *Servers) IsSetTXT(name string) (bool, error)
- func (s *Servers) IsWildcard(name string, t uint16) (bool, error)
- func (s *Servers) QueryA(name string) ([]net.IP, error)
- func (s *Servers) QueryAAAA(name string) ([]net.IP, error)
- func (s *Servers) QueryAll(name string) ([]Record, error)
- func (s *Servers) QueryCAA(name string) ([]CAA, error)
- func (s *Servers) QueryCNAME(name string) ([]string, error)
- func (s *Servers) QueryDNAME(name string) (string, error)
- func (s *Servers) QueryMX(name string) ([]MX, error)
- func (s *Servers) QueryNS(name string) ([]string, error)
- func (s *Servers) QuerySOA(name string) (*SOA, error)
- func (s *Servers) QuerySRV(name string) ([]SRV, error)
- func (s *Servers) QueryTXT(name string) ([]string, error)
- func (s *Servers) SetMaxRetries(n int)
- func (s *Servers) TryQuery(name string, t uint16) ([]mdns.RR, error)
- func (s *Servers) TryQueryA(name string) ([]net.IP, error)
- func (s *Servers) TryQueryAAAA(name string) ([]net.IP, error)
- func (s *Servers) TryQueryCAA(name string) ([]CAA, error)
- func (s *Servers) TryQueryCNAME(name string) ([]string, error)
- func (s *Servers) TryQueryDNAME(name string) (string, error)
- func (s *Servers) TryQueryMX(name string) ([]MX, error)
- func (s *Servers) TryQueryNS(name string) ([]string, error)
- func (s *Servers) TryQuerySOA(name string) (*SOA, error)
- func (s *Servers) TryQuerySRV(name string) ([]SRV, error)
- func (s *Servers) TryQueryTXT(name string) ([]string, error)
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultServers is the package default servers. // It is set in the init(). // Used servers: "8.8.8.8", "1.1.1.1", "9.9.9.10", "1.0.0.1", "8.8.4.4", "149.112.112.10" DefaultServers Servers // DefaultMaxRetries is the default number of retries of failed queries. // Must be greater than 1, else functions will fail with ErrInvalidMaxRetries. DefaultMaxRetries int = 5 // DefaultQueryTimeoutSec is the default query timeout in seconds. DefaultQueryTimeoutSec = 2 )
var ( ErrInvalidMaxRetries = errors.New("invalid MaxRetries") ErrTruncated = errors.New("message is truncated") )
var ( ErrNoError = errors.New("NOERROR") // NOERROR ErrFormat = errors.New("FORMERR") // FORMERR ErrServerFailure = errors.New("SERVFAIL") // SERVFAIL ErrName = errors.New("NXDOMAIN") // NXDOMAIN ErrNotImplemented = errors.New("NOTIMP") // NOTIMP ErrRefused = errors.New("REFUSED") // REFUSED )
var TypeA uint16 = 1
var TypeAAAA uint16 = 28
var TypeCAA uint16 = 257
var TypeCNAME uint16 = 5
var TypeDNAME uint16 = 39
var TypeMX uint16 = 15
var TypeNS uint16 = 2
var TypeSOA uint16 = 6
var TypeSRV uint16 = 33
var TypeTXT uint16 = 16
Functions ¶
func GetDomain ¶
GetDomain returns the domain of d (eg.: sub.example.com -> example.com).
Returns an empty string ("") if d is empty, a dot ("."), starts with a dot (eg.: ".example.com") or d is just a TLD.
func GetDomainIndex ¶
GetDomainIndex returns the index of the domain of d (eg.: sub.example.com -> 4).
Returns -1 if d is empty, a dot ("."), starts with a dot (eg.: ".example.com") or d is just a TLD.
func GetSub ¶
GetSub returns the Subdomain of the given domain d (eg.: eg.: sub.example.com -> example.com). If d is invalid or cant get the subdomain returns an empty string ("").
func GetTLD ¶
GetTLD returns the Top Level Domain of d (eg.: sub.exmaple.com -> com).
Returns an empty string ("") if d is empty, a dot (".") or starts with a dot (eg.: ".example.com").
func GetTLDIndex ¶
GetTLDIndex returns the index of the Top Level Domain in d (eg.: sub.example.com -> 12).
Returns 0 if d is a TLD.
Returns -1 if d is empty, a dot (".") or starts with a dot (eg.: ".example.com").
func IsExists ¶
IsExists checks whether a record with type A, AAAA, TXT, CNAME, MX, NS, CAA or SRV is set for name. NXDOMAIN is not an error here, because it means "not found".
If found a setted record, this function returns without trying for the other types.
func IsSetA ¶
IsSetA checks whether an A type record set for name using the DefaultServers. NXDOMAIN is not an error here, because it means "not found".
func IsSetAAAA ¶
IsSetAAAA checks whether an AAAA type record set for name using the DefaultServers. NXDOMAIN is not an error here, because it means "not found".
func IsSetCAA ¶
IsSetCAA checks whether a CAA type record set for name using the DefaultServers. NXDOMAIN is not an error here, because it means "not found".
func IsSetCNAME ¶
IsSetCNAME checks whether an CNAME type record set for name using the DefaultServers. NXDOMAIN is not an error here, because it means "not found".
func IsSetDNAME ¶
IsSetCNAME checks whether an DNAME type record set for name using the DefaultServers. NXDOMAIN is not an error here, because it means "not found".
func IsSetMX ¶
IsSetMX checks whether an MX type record set for name using the DefaultServers. NXDOMAIN is not an error here, because it means "not found".
func IsSetNS ¶
IsSetNS checks whether an NS type record set for name using the DefaultServers. NXDOMAIN is not an error here, because it means "not found".
func IsSetSOA ¶
IsSetSOA checks whether an SOA type record set for name using the DefaultServers. NXDOMAIN is not an error here, because it means "not found".
func IsSetSRV ¶
IsSetSRV checks whether an SRV type record set for name using the DefaultServers. NXDOMAIN is not an error here, because it means "not found".
func IsSetTXT ¶
IsSetTXT checks whether an TXT type record set for name using the DefaultServers. NXDOMAIN is not an error here, because it means "not found".
func IsValidSLD
deprecated
func IsWildcard ¶
IsWildcard uses the DefaultServers to check if name is a wildcard domain.
NOTE: Use IsValid() and Clean() before this function!
func Probe ¶
Probe checks whether DNS protocol is available on network on ip:port. This function do a simple query with "example.com."/"A". network must be "tcp", "tcp-tls" or "udp".
func QueryA ¶
QueryA ask a random server from DefaultServers and returns a slice of net.IP. The answer slice will be nil in case of error.
The other record types are ignored.
func QueryAAAA ¶
QueryAAAA ask a random server from DefaultServers and returns a slice of net.IP. The answer slice will be nil in case of error.
The other record types are ignored.
func QueryCNAME ¶
QueryCNAME ask a random server from DefaultServers and returns a slice of string. The answer slice will be nil in case of error.
The other record types are ignored.
func QueryDNAME ¶
QueryDNAME ask a random server from DefaultServers and returns the target of string. The answer slice will be nil in case of error.
The other record types are ignored.
func QueryNS ¶
QueryNS ask a random server from DefaultServers and returns a slice of string. The answer slice will be nil in case of error.
The other record types are ignored.
func QueryTXT ¶
QueryTXT ask a random server from DefaultServers and returns a slice of string. The answer slice will be nil in case of error.
The other record types are ignored.
func RcodeToError ¶
RcodeToError returns the error associated with the rcode. If rcode is unknown, returns rcode.
func TryQueryA ¶
TryQueryA asks the DefaultServers for type A. If any error occurred, retries with next server (except if error is NXDOMAIN).
In case of error, the answer will be nil and return ErrX or any unknown error.
The first used server is random. The other record types are ignored.
func TryQueryAAAA ¶
TryQueryAAAA asks the DefaultServers for type A. If any error occurred, retries with next server (except if error is NXDOMAIN).
In case of error, the answer will be nil and return ErrX or any unknown error.
The first used server is random. The other record types are ignored.
func TryQueryCNAME ¶
TryQueryCNAME asks the DefaultServers for type CNAME. If any error occurred, retries with next server (except if error is NXDOMAIN).
In case of error, the answer will be nil and return ErrX or any unknown error.
The first used server is random. The other record types are ignored.
func TryQueryDNAME ¶
TryQueryDNAME asks the DefaultServers for type DNAME. If any error occurred, retries with next server (except if error is NXDOMAIN).
In case of error, the answer will be nil and return ErrX or any unknown error.
The first used server is random. The other record types are ignored.
func TryQueryNS ¶
TryQueryNS asks the DefaultServers for type NS. If any error occurred, retries with next server (except if error is NXDOMAIN).
In case of error, the answer will be nil and return ErrX or any unknown error.
The first used server is random. The other record types are ignored.
func TryQueryTXT ¶
TryQueryTXT asks the DefaultServers for type TXT. If any error occurred, retries with next server (except if error is NXDOMAIN).
In case of error, the answer will be nil and return ErrX or any unknown error.
The first used server is random. The other record types are ignored.
func TypeToString ¶
Types ¶
type CAA ¶
func QueryCAA ¶
QueryCAA ask a random server from DefaultServers and returns a slice of CAA. The answer slice will be nil in case of error.
The other record types are ignored.
func TryQueryCAA ¶
TryQueryCAA asks the DefaultServers for type CAA. If any error occurred, retries with next server (except if error is NXDOMAIN).
In case of error, the answer will be nil and return ErrX or any unknown error.
The first used server is random. The other record types are ignored.
type MX ¶
func QueryMX ¶
QueryMX ask a random server from DefaultServers and returns a slice of MX. The answer slice will be nil in case of error.
The other record types are ignored.
func TryQueryMX ¶
TryQueryMX asks the DefaultServers for type MX. If any error occurred, retries with next server (except if error is NXDOMAIN).
In case of error, the answer will be nil and return ErrX or any unknown error.
The first used server is random. The other record types are ignored.
type Parts ¶
type Parts struct { TLD string // Top level domain (eg.: "com"). Cant be empty. Domain string // Domain part (eg.: example"). Cant be empty. Sub string // Subdomain part (eg.: "www"). Can be empty. }
func GetParts ¶
GetParts returns the parts of d.
If d is just a TLD, returns a struct with empty Domain (eg.: "com" -> &Result{Sub: "", Domain: "", TLD: "com"}).
If d does not contains subdomain, than Sub will be empty (eg.: "example.com" -> &Result{Sub: "", Domain: "example", TLD: "com"}).
Returns nil if d is empty, a dot (".") or starts with a dot (eg.: ".example.com").
NOTE: This function does not validate and Clean() the given domain d. It is recommended to use IsValid() and Clean() before this function.
type SOA ¶
type SOA struct { Mname string Rname string Serial int Refresh int Retry int Expire int MinTTL int }
See more: https://www.rfc-editor.org/rfc/rfc1035.html#section-3.3.13
func QuerySOA ¶
QuerySOA ask a random server from DefaultServers and returns a SOA struct pointer. The answer slice will be nil in case of error.
The other record types are ignored.
func TryQuerySOA ¶
TryQuerySOA asks the DefaultServers for type SOA. If any error occurred, retries with next server (except if error is NXDOMAIN).
In case of error, the answer will be nil and return ErrX or any unknown error.
The first used server is random. The other record types are ignored.
type SRV ¶
func QuerySRV ¶
QuerySRV ask a random server from DefaultServers and returns a slice of SRV. The answer slice will be nil in case of error.
The other record types are ignored.
func TryQuerySRV ¶
TryQuerySRV asks the DefaultServers for type SRV. If any error occurred, retries with next server (except if error is NXDOMAIN).
In case of error, the answer will be nil and return ErrX or any unknown error.
The first used server is random. The other record types are ignored.
type Server ¶
type Server struct { Protocol string // Protocol name, must be "udp", "tcp" or "tcp-tls" IP string // Ip address Port string // Destination port // contains filtered or unexported fields }
func NewServerStr ¶
NewServerStr creates a Server from string s.
String format:
[protocol://]ip[:port]
If protocol is missing, defaults to "udp". Valid protocols are: "udp", "tcp" and "tcp-tls".
If port is missing, defaults to "53".
Valid strings:
- udp://127.0.0.1:53 -> UDP query to 127.0.0.1 on port 53 (IPv4)
- udp://[::1]:53 -> UDP query to ::1 on port 53 (IPv6)
- udp://127.0.0.1 -> UDP query to 127.0.0.1 on port 53
- 127.0.0.1:53 -> UDP query to 127.0.0.1 on port 53
- 127.0.0.1 -> UDP query to 127.0.0.1 on port 53
func (*Server) QueryA ¶
QueryA ask the server and returns a slice of net.IP. The answer slice will be nil in case of error.
The other record types are ignored.
func (*Server) QueryAAAA ¶
QueryAAAA ask the server and returns a slice of net.IP. The answer slice will be nil in case of error.
The other record types are ignored.
func (*Server) QueryCAA ¶
QueryCAA ask the server and returns a slice of CAA. The answer slice will be nil in case of error.
The other record types are ignored.
func (*Server) QueryCNAME ¶
QueryCNAME ask the server and returns a slice of string. The answer slice will be nil in case of error.
The other record types are ignored.
func (*Server) QueryDNAME ¶
QueryDNAME ask the server and returns the target string. The answer slice will be nil in case of error.
The other record types are ignored.
func (*Server) QueryMX ¶
QueryMX ask the server and returns a slice of MX. The answer slice will be nil in case of error.
The other record types are ignored.
func (*Server) QueryNS ¶
QueryNS ask the server and returns a slice of string. The answer slice will be nil in case of error.
The other record types are ignored.
func (*Server) QuerySOA ¶
QuerySOA ask the server and returns a SOA struct pointer. The answer slice will be nil in case of error.
The other record types are ignored.
func (*Server) QuerySRV ¶
QuerySRV ask the server and returns a slice of SRV. The answer slice will be nil in case of error.
The other record types are ignored.
func (*Server) QueryTXT ¶
QueryTXT ask the server and returns a slice of string. The answer slice will be nil in case of error.
The other record types are ignored.
type Servers ¶
type Servers struct {
// contains filtered or unexported fields
}
func NewServersSlice ¶
NewServersSlice creates a new Servers from srvs. Retries is the maximum number retries allowed in TryQuery function.
func NewServersStr ¶
NewServersStr creates a new Servers from srvs. The protocol must be "udp", "tcp" or "tcp-tls". The ddefault protocol is "udp" and the default port is "53". Retries is the maximum number retries allowed in TryQuery function. Timeout is a cumulative timeout for dial.
func (*Servers) Get ¶
Get returns a DNS server to use. If index is between the servers range, returns the selected server. If index is not between the servers range, returns a random one.
Set index to -1 to get a random one.
func (*Servers) GetMaxRetries ¶
GetMaxRetries returns the maximum number retries configured in the Servers.
func (*Servers) IsSet ¶
IsSet checks whether a record with type t is set for name. This function retries the query in case of error (**NOT** errors like NXDOMAIN) up to n times (configured when created the Servers). NXDOMAIN is not an error here, because it means "not found".
func (*Servers) IsSetA ¶
IsSetA checks whether an A type record set for name. NXDOMAIN is not an error here, because it means "not found".
func (*Servers) IsSetAAAA ¶
IsSetAAAA checks whether an AAAA type record set for name. NXDOMAIN is not an error here, because it means "not found".
func (*Servers) IsSetCAA ¶
IsSetCAA checks whether a CAA type record set for name. NXDOMAIN is not an error here, because it means "not found".
func (*Servers) IsSetCNAME ¶
IsSetCNAME checks whether an CNAME type record set for name. NXDOMAIN is not an error here, because it means "not found".
func (*Servers) IsSetDNAME ¶
IsSetDNAME checks whether an DNAME type record set for name. NXDOMAIN is not an error here, because it means "not found".
func (*Servers) IsSetMX ¶
IsSetMX checks whether an MX type record set for name. NXDOMAIN is not an error here, because it means "not found".
func (*Servers) IsSetNS ¶
IsSetNS checks whether an NS type record set for name. NXDOMAIN is not an error here, because it means "not found".
func (*Servers) IsSetSOA ¶
IsSetSOA checks whether an SOA type record set for name. NXDOMAIN is not an error here, because it means "not found".
func (*Servers) IsSetSRV ¶
IsSetSRV checks whether an SRV type record set for name. NXDOMAIN is not an error here, because it means "not found".
func (*Servers) IsSetTXT ¶
IsSetTXT checks whether an TXT type record set for name. NXDOMAIN is not an error here, because it means "not found".
func (*Servers) IsWildcard ¶
IsWildcard check if name is a wildcard domain.
NOTE: Use IsValid() and Clean() before this function!
func (*Servers) QueryA ¶
QueryA ask a random server from servers and returns a slice of net.IP. The answer slice will be nil in case of error.
The other record types are ignored.
func (*Servers) QueryAAAA ¶
QueryAAAA ask a random server from servers and returns a slice of net.IP. The answer slice will be nil in case of error.
The other record types are ignored.
func (*Servers) QueryAll ¶
QueryAll query every known type and returns the records. This function checks whether name with the type is a wildcard, and if name is a wildcard, ommit from the retuned []Record.
It is possible to return records when error returned.
func (*Servers) QueryCAA ¶
QueryCAA ask a random server from servers and returns a slice of CAA. The answer slice will be nil in case of error.
The other record types are ignored.
func (*Servers) QueryCNAME ¶
QueryCNAME ask a random server from servers and returns a slice of string. The answer slice will be nil in case of error.
The other record types are ignored.
func (*Servers) QueryDNAME ¶
QueryDNAME ask a random server from servers and returns the target string. The answer slice will be nil in case of error.
The other record types are ignored.
func (*Servers) QueryMX ¶
QueryMX ask a random server from servers and returns a slice of MX. The answer slice will be nil in case of error.
The other record types are ignored.
func (*Servers) QueryNS ¶
QueryNS ask a random server from servers and returns a slice of string. The answer slice will be nil in case of error.
The other record types are ignored.
func (*Servers) QuerySOA ¶
QuerySOA ask a random server from servers and returns a SOA struct pointer. The answer slice will be nil in case of error.
The other record types are ignored.
func (*Servers) QuerySRV ¶
QuerySRV ask a random server from servers and returns a slice of SRV. The answer slice will be nil in case of error.
The other record types are ignored.
func (*Servers) QueryTXT ¶
QueryTXT ask a random server from servers and returns a slice of string. The answer slice will be nil in case of error.
The other record types are ignored.
func (*Servers) SetMaxRetries ¶
SetMaxRetries sets the maximum number retries in the Servers.
func (*Servers) TryQuery ¶
TryQuery asks the servers for type t. If any error occurred, retries with an other server (except if error is NXDOMAIN). Returns the Answer section. In case of error, the answer will be nil and return ErrX or any unknown error.
NOTE: The first used server is random.
func (*Servers) TryQueryA ¶
TryQueryA asks the servers for type A. If any error occurred, retries with next server (except if error is NXDOMAIN).
In case of error, the answer will be nil and return ErrX or any unknown error.
The first used server is random. The other record types are ignored.
func (*Servers) TryQueryAAAA ¶
TryQueryAAAA asks the servers for type AAAA. If any error occurred, retries with next server (except if error is NXDOMAIN).
In case of error, the answer will be nil and return ErrX or any unknown error.
The first used server is random. The other record types are ignored.
func (*Servers) TryQueryCAA ¶
TryQueryCAA asks the servers for type CAA. If any error occurred, retries with next server (except if error is NXDOMAIN).
In case of error, the answer will be nil and return ErrX or any unknown error.
The first used server is random. The other record types are ignored.
func (*Servers) TryQueryCNAME ¶
TryQueryCNAME asks the servers for type CNAME. If any error occurred, retries with next server (except if error is NXDOMAIN).
In case of error, the answer will be nil and return ErrX or any unknown error.
The first used server is random. The other record types are ignored.
func (*Servers) TryQueryDNAME ¶
TryQueryDNAME asks the servers for type DNAME. If any error occurred, retries with next server (except if error is NXDOMAIN).
In case of error, the answer will be nil and return ErrX or any unknown error.
The first used server is random. The other record types are ignored.
func (*Servers) TryQueryMX ¶
TryQueryMX asks the servers for type MX. If any error occurred, retries with next server (except if error is NXDOMAIN).
In case of error, the answer will be nil and return ErrX or any unknown error.
The first used server is random. The other record types are ignored.
func (*Servers) TryQueryNS ¶
TryQueryNS asks the servers for type NS. If any error occurred, retries with next server (except if error is NXDOMAIN).
In case of error, the answer will be nil and return ErrX or any unknown error.
The first used server is random. The other record types are ignored.
func (*Servers) TryQuerySOA ¶
TryQuerySOA asks the servers for type SOA. If any error occurred, retries with next server (except if error is NXDOMAIN).
In case of error, the answer will be nil and return ErrX or any unknown error.
The first used server is random. The other record types are ignored.
func (*Servers) TryQuerySRV ¶
TryQuerySRV asks the servers for type SRV. If any error occurred, retries with next server (except if error is NXDOMAIN).
In case of error, the answer will be nil and return ErrX or any unknown error.
The first used server is random. The other record types are ignored.
func (*Servers) TryQueryTXT ¶
TryQueryTXT asks the servers for type TXT. If any error occurred, retries with next server (except if error is NXDOMAIN).
In case of error, the answer will be nil and return ErrX or any unknown error.
The first used server is random. The other record types are ignored.