mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2025-01-03 04:50:11 +00:00
42 lines
827 B
Go
42 lines
827 B
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net"
|
|
|
|
"github.com/miekg/dns"
|
|
)
|
|
|
|
type DNSResult struct {
|
|
msg *dns.Msg
|
|
err error
|
|
}
|
|
|
|
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
|
|
}
|