SpoofDPI/dns/resolver/general.go

37 lines
777 B
Go
Raw Permalink Normal View History

2024-08-19 02:00:26 +00:00
package resolver
2024-08-18 06:55:47 +00:00
import (
"context"
"fmt"
"net"
"github.com/miekg/dns"
)
2024-08-18 07:11:04 +00:00
type GeneralResolver struct {
client *dns.Client
2024-08-18 06:55:47 +00:00
server string
}
func NewGeneralResolver(server string) *GeneralResolver {
2024-08-18 07:11:04 +00:00
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 09:51:20 +00:00
resultCh := lookupAllTypes(ctx, host, qTypes, r.exchange)
2024-08-18 06:55:47 +00:00
addrs, err := processResults(ctx, resultCh)
return addrs, err
}
func (r *GeneralResolver) String() string {
return fmt.Sprintf("general resolver(%s)", r.server)
2024-08-18 06:55:47 +00:00
}
2024-08-18 09:51:20 +00:00
func (r *GeneralResolver) exchange(ctx context.Context, msg *dns.Msg) (*dns.Msg, error) {
resp, _, err := r.client.Exchange(msg, r.server)
return resp, err
}