SpoofDPI/dns/resolver/general.go
2024-08-19 11:00:26 +09:00

37 lines
777 B
Go

package resolver
import (
"context"
"fmt"
"net"
"github.com/miekg/dns"
)
type GeneralResolver struct {
client *dns.Client
server string
}
func NewGeneralResolver(server string) *GeneralResolver {
return &GeneralResolver{
client: &dns.Client{},
server: server,
}
}
func (r *GeneralResolver) Resolve(ctx context.Context, host string, qTypes []uint16) ([]net.IPAddr, error) {
resultCh := lookupAllTypes(ctx, host, qTypes, r.exchange)
addrs, err := processResults(ctx, resultCh)
return addrs, err
}
func (c *GeneralResolver) String() string {
return fmt.Sprintf("general resolver(%s)", c.server)
}
func (r *GeneralResolver) exchange(ctx context.Context, msg *dns.Msg) (*dns.Msg, error) {
resp, _, err := r.client.Exchange(msg, r.server)
return resp, err
}