SpoofDPI/dns/resolver/general.go

42 lines
799 B
Go
Raw Normal View History

2024-08-18 06:55:47 +00:00
package client
import (
"context"
"fmt"
"net"
"github.com/miekg/dns"
)
type DNSResult struct {
msg *dns.Msg
err error
}
2024-08-18 07:11:04 +00:00
type GeneralResolver struct {
client *dns.Client
2024-08-18 06:55:47 +00:00
server string
}
2024-08-18 07:11:04 +00:00
func NewGeneralClient(server string) *GeneralResolver {
return &GeneralResolver{
client: &dns.Client{},
2024-08-18 06:55:47 +00:00
server: server,
}
}
2024-08-18 07:11:04 +00:00
func (r *GeneralResolver) Resolve(ctx context.Context, host string, qTypes []uint16) ([]net.IPAddr, error) {
2024-08-18 06:55:47 +00:00
sendMsg := func(ctx context.Context, msg *dns.Msg) (*dns.Msg, error) {
2024-08-18 07:11:04 +00:00
resp, _, err := r.client.Exchange(msg, r.server)
2024-08-18 06:55:47 +00:00
return resp, err
}
resultCh := lookup(ctx, host, qTypes, sendMsg)
addrs, err := processResults(ctx, resultCh)
return addrs, err
}
2024-08-18 07:11:04 +00:00
func (c *GeneralResolver) String() string {
2024-08-18 07:33:02 +00:00
return fmt.Sprintf("general resolver(%s)", c.server)
2024-08-18 06:55:47 +00:00
}