diff --git a/dns/dns.go b/dns/dns.go index 8768974..4eec77b 100644 --- a/dns/dns.go +++ b/dns/dns.go @@ -26,18 +26,25 @@ type Dns struct { systemClient Resolver generalClient Resolver dohClient Resolver + qTypes []uint16 } func NewDns(config *util.Config) *Dns { addr := config.DnsAddr port := strconv.Itoa(config.DnsPort) - + var qTypes []uint16 + if config.DnsIPv4Only { + qTypes = []uint16{dns.TypeA} + } else { + qTypes = []uint16{dns.TypeAAAA, dns.TypeA} + } return &Dns{ host: config.DnsAddr, port: port, systemClient: resolver.NewSystemResolver(), generalClient: resolver.NewGeneralResolver(net.JoinHostPort(addr, port)), dohClient: resolver.NewDOHResolver(addr), + qTypes: qTypes, } } @@ -57,7 +64,7 @@ func (d *Dns) ResolveHost(ctx context.Context, host string, enableDoh bool, useS t := time.Now() - addrs, err := clt.Resolve(ctx, host, []uint16{dns.TypeAAAA, dns.TypeA}) + addrs, err := clt.Resolve(ctx, host, d.qTypes) // addrs, err := clt.Resolve(ctx, host, []uint16{dns.TypeAAAA}) if err != nil { return "", fmt.Errorf("%s: %w", clt, err) diff --git a/util/args.go b/util/args.go index 2bfe72f..ec9921a 100644 --- a/util/args.go +++ b/util/args.go @@ -13,6 +13,7 @@ type Args struct { Port uint16 DnsAddr string DnsPort uint16 + DnsIPv4Only bool EnableDoh bool Debug bool Silent bool @@ -57,6 +58,7 @@ fragmentation for the first data packet and the rest "pattern", "bypass DPI only on packets matching this regex pattern; can be given multiple times", ) + flag.BoolVar(&args.DnsIPv4Only, "dns-ipv4-only", false, "resolve only version 4 addresses") flag.Parse() diff --git a/util/config.go b/util/config.go index d58423b..ffce1b0 100644 --- a/util/config.go +++ b/util/config.go @@ -13,6 +13,7 @@ type Config struct { Port int DnsAddr string DnsPort int + DnsIPv4Only bool EnableDoh bool Debug bool Silent bool @@ -36,6 +37,7 @@ func (c *Config) Load(args *Args) { c.Port = int(args.Port) c.DnsAddr = args.DnsAddr c.DnsPort = int(args.DnsPort) + c.DnsIPv4Only = args.DnsIPv4Only c.Debug = args.Debug c.EnableDoh = args.EnableDoh c.Silent = args.Silent