2021-11-16 14:22:01 +00:00
|
|
|
package dnsdisc
|
2021-09-30 23:03:19 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net"
|
|
|
|
)
|
|
|
|
|
2021-11-05 20:09:48 +00:00
|
|
|
// GetResolver returns a *net.Resolver object using a custom nameserver, or
|
|
|
|
// the default system resolver if no nameserver is specified
|
2021-09-30 23:03:19 +00:00
|
|
|
func GetResolver(ctx context.Context, nameserver string) *net.Resolver {
|
|
|
|
if nameserver == "" {
|
|
|
|
return net.DefaultResolver
|
|
|
|
}
|
|
|
|
|
|
|
|
return &net.Resolver{
|
|
|
|
PreferGo: true,
|
2024-01-15 14:42:02 +00:00
|
|
|
Dial: func(_ context.Context, network, address string) (net.Conn, error) {
|
2021-09-30 23:03:19 +00:00
|
|
|
d := net.Dialer{}
|
|
|
|
return d.DialContext(ctx, network, net.JoinHostPort(nameserver, "53"))
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|