Documentation
¶
Index ¶
- Variables
- type A
- type AAAA
- type Client
- func (c *Client) NameServer() *NameServer
- func (c *Client) QueryA(name string) ([]A, error)
- func (c *Client) QueryAAAA(name string) ([]AAAA, error)
- func (c *Client) QueryHTTPS(name string) ([]HTTPS, error)
- func (c *Client) QueryNS(name string) ([]NS, error)
- func (c *Client) QuerySOA(name string) (*SOA, error)
- func (c *Client) QuerySVCB(name string) ([]SVCB, error)
- type HTTPS
- type NS
- type NameServer
- type Rcode
- type SOA
- type SVCB
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // CloudflareDNS is a predefined [Client] to use the Cloudflare DNS servers. CloudflareDNS = &Client{ NameServers: []NameServer{ {protocol: "udp", host: "1.1.1.1", port: "53"}, {protocol: "udp", host: "1.0.0.1", port: "53"}, }, Timeout: 5 * time.Second, Attempts: 2, } // GoogleDNS is a predefined [Client] to use the Google DNS servers. GoogleDNS = &Client{ NameServers: []NameServer{ {protocol: "udp", host: "8.8.8.8", port: "53"}, {protocol: "udp", host: "8.8.8.4", port: "53"}, }, Timeout: 5 * time.Second, Attempts: 2, } // CommonDNS is a predefined [Client] to use the common DNS servers (currently Cloudflare and Google). CommonDNS *Client = &Client{ NameServers: []NameServer{ {protocol: "udp", host: "1.1.1.1", port: "53"}, {protocol: "udp", host: "1.0.0.1", port: "53"}, {protocol: "udp", host: "8.8.8.8", port: "53"}, {protocol: "udp", host: "8.8.8.4", port: "53"}, }, Timeout: 5 * time.Second, Attempts: 2, } )
Functions ¶
This section is empty.
Types ¶
type A ¶
func QueryA ¶
QueryA uses DefaultClient to query the a NameServer returned by Client.NameServer.
Example ¶
package main
import (
"fmt"
"git.gorbe.io/go/dns"
)
func main() {
records, err := dns.QueryA("example.com")
if err != nil {
// Handle error
return
}
for i := range records {
fmt.Printf("%s\n", records[i])
}
}
Output:
type AAAA ¶
func QueryAAAA ¶
QueryAAAA uses DefaultClient to query the a NameServer returned by Client.NameServer.
Example ¶
package main
import (
"fmt"
"git.gorbe.io/go/dns"
)
func main() {
records, err := dns.QueryAAAA("example.com")
if err != nil {
// Handle error
return
}
for i := range records {
fmt.Printf("%s\n", records[i])
}
}
Output:
type Client ¶
type Client struct {
NameServers []NameServer
Timeout time.Duration
Attempts int // TODO
}
var ( // DefaultClient is used by QueryX functions. // // Package dns tries to parse "/etc/resolv.conf" into [DefaultClient] with [ParseResolvConf]. // If failed to parse "/etc/resolv.conf" sets to [CommonDNS]. DefaultClient *Client )
func ParseResolvConf ¶
ParseResolvConf parses a resolv.conf style file in path name.
func (*Client) NameServer ¶
func (c *Client) NameServer() *NameServer
NameServer returns a random nameserver from the stored nameservers.
func (*Client) QueryA ¶
QueryA queries the next NameServer returned by Client.NameServer.
Example ¶
package main
import (
"fmt"
"git.gorbe.io/go/dns"
)
func main() {
c, err := dns.ParseResolvConf("/etc/resolv.conf")
if err != nil {
// Handle error
return
}
records, err := c.QueryA("example.com")
if err != nil {
// Handle error
return
}
for i := range records {
fmt.Printf("%s\n", records[i])
}
}
Output:
func (*Client) QueryAAAA ¶
QueryAAAA queries the next NameServer returned by Client.NameServer.
Example ¶
package main
import (
"fmt"
"git.gorbe.io/go/dns"
)
func main() {
c, err := dns.ParseResolvConf("/etc/resolv.conf")
if err != nil {
// Handle error
return
}
records, err := c.QueryAAAA("example.com")
if err != nil {
// Handle error
return
}
for i := range records {
fmt.Printf("%s\n", records[i])
}
}
Output:
func (*Client) QueryHTTPS ¶
QueryHTTPS queries the next NameServer returned by Client.NameServer.
Example ¶
package main
import (
"fmt"
"git.gorbe.io/go/dns"
)
func main() {
c, err := dns.ParseResolvConf("/etc/resolv.conf")
if err != nil {
// Handle error
return
}
records, err := c.QueryHTTPS("google.com")
if err != nil {
// Handle error
return
}
for i := range records {
fmt.Printf("%s\n", records[i])
}
}
Output:
func (*Client) QueryNS ¶
QueryNS queries the next NameServer returned by Client.NameServer.
func (*Client) QuerySOA ¶
QuerySOA queries the next NameServer returned by Client.NameServer.
If return nil/nil, then no SOA record found in the answer section.
Example ¶
package main
import (
"fmt"
"git.gorbe.io/go/dns"
)
func main() {
c, err := dns.ParseResolvConf("/etc/resolv.conf")
if err != nil {
// Handle error
return
}
record, err := c.QuerySOA("example.com")
if err != nil {
// Handle error
return
}
fmt.Printf("%s\n", record)
}
Output:
func (*Client) QuerySVCB ¶
QuerySVCB queries the next NameServer returned by Client.NameServer.
Example ¶
package main
import (
"fmt"
"git.gorbe.io/go/dns"
)
func main() {
c, err := dns.ParseResolvConf("/etc/resolv.conf")
if err != nil {
// Handle error
return
}
records, err := c.QuerySVCB("google.com")
if err != nil {
// Handle error
return
}
for i := range records {
fmt.Printf("%s\n", records[i])
}
}
Output:
type HTTPS ¶
func QueryHTTPS ¶
type NameServer ¶
type NameServer struct {
// contains filtered or unexported fields
}
Example ¶
package main
import (
"fmt"
"git.gorbe.io/go/dns"
)
func main() {
ns, err := dns.NewNameServer("", "127.0.0.1", "")
if err != nil {
// Handle error
}
fmt.Printf("%s\n", ns)
}
Output: 127.0.0.1:53
func NewNameServer ¶
func NewNameServer(protocol, host string, port string) (NameServer, error)
NewNameServer sets the default values and a NameServer.
- If protocol is empty, sets to "udp" - If hostname is empty, returns an error - If port is empty, sets to "53"
func (*NameServer) Host ¶
func (ns *NameServer) Host() string
Host returns the set host for NameServer ns.
func (*NameServer) Port ¶
func (ns *NameServer) Port() string
Port returns the set port for NameServer ns.
If the port is unset, sets to "53".
func (*NameServer) Protocol ¶
func (ns *NameServer) Protocol() string
Protocol returns the set protocol for NameServer ns.
If the protocol is unset, sets to "udp".
func (NameServer) String ¶
func (ns NameServer) String() string
String implements the fmt.Stringer interface. Returns the nameserver's address in the following format:
[host]:port
type Rcode ¶
type Rcode int
Example ¶
package main
import (
"fmt"
"git.gorbe.io/go/dns"
)
func main() {
rcode := dns.Rcode(3)
fmt.Printf("%s", rcode)
}
Output: NXDOMAIN
type SOA ¶
type SOA struct {
MName string
RName string
Serial uint32
Refresh uint32
Retry uint32
Expire uint32
Minimum uint32
}
func QuerySOA ¶
QuerySOA uses DefaultClient to query the a NameServer returned by Client.NameServer.
Example ¶
package main
import (
"fmt"
"git.gorbe.io/go/dns"
)
func main() {
record, err := dns.QuerySOA("example.com")
if err != nil {
// Handle error
return
}
fmt.Printf("%s\n", record)
}
Output: