SpoofDPI/dns/client/general.go

41 lines
759 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 06:58:11 +00:00
type GeneralClient struct {
2024-08-18 06:55:47 +00:00
server string
}
2024-08-18 06:58:11 +00:00
func NewGeneralClient(server string) *GeneralClient {
return &GeneralClient{
2024-08-18 06:55:47 +00:00
server: server,
}
}
2024-08-18 06:58:11 +00:00
func (c *GeneralClient) 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) {
clt := &dns.Client{}
resp, _, err := clt.Exchange(msg, c.server)
return resp, err
}
resultCh := lookup(ctx, host, qTypes, sendMsg)
addrs, err := processResults(ctx, resultCh)
return addrs, err
}
2024-08-18 06:58:11 +00:00
func (c *GeneralClient) String() string {
2024-08-18 06:55:47 +00:00
return fmt.Sprintf("custom client(%s)", c.server)
}