mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
624 B
36 lines
624 B
package dns
|
|
|
|
import (
|
|
"context"
|
|
|
|
"v2ray.com/core/common/net"
|
|
)
|
|
|
|
type NameServer interface {
|
|
QueryIP(ctx context.Context, domain string) ([]net.IP, error)
|
|
}
|
|
|
|
type localNameServer struct {
|
|
resolver net.Resolver
|
|
}
|
|
|
|
func (s *localNameServer) QueryIP(ctx context.Context, domain string) ([]net.IP, error) {
|
|
ipAddr, err := s.resolver.LookupIPAddr(ctx, domain)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var ips []net.IP
|
|
for _, addr := range ipAddr {
|
|
ips = append(ips, addr.IP)
|
|
}
|
|
return ips, nil
|
|
}
|
|
|
|
func NewLocalNameServer() *localNameServer {
|
|
return &localNameServer{
|
|
resolver: net.Resolver{
|
|
PreferGo: true,
|
|
},
|
|
}
|
|
}
|