diff --git a/cmd/cli.go b/cmd/cli.go index 5d10203..8cb2979 100644 --- a/cmd/cli.go +++ b/cmd/cli.go @@ -35,12 +35,6 @@ func main() { f.StringSliceP("class", "c", []string{}, "Network class of the DNS record to be queried (IN, CH, HS etc)") f.StringSliceP("nameserver", "n", []string{}, "Address of the nameserver to send packets to") - // Protocol Options - f.BoolP("udp", "U", false, "Use the DNS protocol over UDP") - f.BoolP("tcp", "T", false, "Use the DNS protocol over TCP") - f.BoolP("doh", "H", false, "Use the DNS-over-HTTPS protocol") - f.BoolP("dot", "S", false, "Use the DNS-over-TLS") - // Resolver Options f.Int("timeout", 5, "Sets the timeout for a query to T seconds. The default timeout is 5 seconds.") f.Bool("search", false, "Use the search list provided in resolv.conf. It sets the `ndots` parameter as well unless overriden by `ndots` flag.") diff --git a/cmd/help.go b/cmd/help.go index 502f2fe..ec82139 100644 --- a/cmd/help.go +++ b/cmd/help.go @@ -34,12 +34,6 @@ var AppHelpTemplate = `{{ "NAME" | color "" "heading" }}: {{"-n, --nameserver=ADDR" | color "yellow" ""}} Address of a specific nameserver to send queries to (9.9.9.9, 1.1.1.1 etc) {{"-c, --class=CLASS" | color "yellow" ""}} Network class of the DNS record (IN, CH, HS etc) -{{ "Protocol Options" | color "" "heading" }}: - {{"-U, --udp " | color "yellow" ""}} Send queries via DNS over UDP protocol - {{"-T, --tcp " | color "yellow" ""}} Send queries via DNS over TCP protocol - {{"-S, --dot " | color "yellow" ""}} Send queries via DNS over TLS (DoT) protocol - {{"-H, --doh" | color "yellow" ""}} Send queries via DNS over HTTPS (DoH) protocol - {{ "Output Options" | color "" "heading" }}: {{"-J, --json " | color "yellow" ""}} Format the output as JSON {{"--color " | color "yellow" ""}} Defaults to true. Set --color=false to disable colored output diff --git a/cmd/hub.go b/cmd/hub.go index a29de11..d6d72ed 100644 --- a/cmd/hub.go +++ b/cmd/hub.go @@ -25,10 +25,6 @@ type QueryFlags struct { QTypes []string `koanf:"type"` QClasses []string `koanf:"class"` Nameservers []string `koanf:"nameserver"` - IsDOH bool `koanf:"doh"` - IsDOT bool `koanf:"dot"` - IsUDP bool `koanf:"udp"` - IsTCP bool `koanf:"tcp"` UseIPv4 bool `koanf:"ipv4"` UseIPv6 bool `koanf:"ipv6"` DisplayTimeTaken bool `koanf:"time"` diff --git a/cmd/parse.go b/cmd/parse.go index bd1d239..8afd4a1 100644 --- a/cmd/parse.go +++ b/cmd/parse.go @@ -28,9 +28,6 @@ func (hub *Hub) loadQueryArgs() error { // pattern it is considered to be a "query name". func (hub *Hub) loadFreeArgs() error { for _, arg := range hub.FreeArgs { - if strings.HasPrefix(arg, "--") || strings.HasPrefix(arg, "-") { - continue - } if strings.HasPrefix(arg, "@") { hub.QueryFlags.Nameservers = append(hub.QueryFlags.Nameservers, strings.Trim(arg, "@")) } else if _, ok := dns.StringToType[strings.ToUpper(arg)]; ok { diff --git a/cmd/resolver.go b/cmd/resolver.go index 1094df5..53b618f 100644 --- a/cmd/resolver.go +++ b/cmd/resolver.go @@ -19,6 +19,10 @@ const ( DefaultTLSPort = "853" // DefaultUDPPort specifies the default port for a DNS server connecting over UDP DefaultUDPPort = "53" + UDPResolver = "udp" + DOHResolver = "doh" + TCPResolver = "tcp" + DOTResolver = "dot" ) // initResolver checks for various flags and initialises @@ -26,7 +30,7 @@ const ( func (hub *Hub) initResolver() error { // for each nameserver, initialise the correct resolver for _, ns := range hub.Nameservers { - if ns.Type == "doh" { + if ns.Type == DOHResolver { hub.Logger.Debug("initiating DOH resolver") rslvr, err := resolvers.NewDOHResolver(ns.Address, resolvers.DOHResolverOpts{ Timeout: hub.QueryFlags.Timeout * time.Second, @@ -36,7 +40,7 @@ func (hub *Hub) initResolver() error { } hub.Resolver = append(hub.Resolver, rslvr) } - if ns.Type == "tcp" { + if ns.Type == TCPResolver { hub.Logger.Debug("initiating TCP resolver") rslvr, err := resolvers.NewTCPResolver(ns.Address, resolvers.TCPResolverOpts{ IPv4Only: hub.QueryFlags.UseIPv4, @@ -48,7 +52,7 @@ func (hub *Hub) initResolver() error { } hub.Resolver = append(hub.Resolver, rslvr) } - if ns.Type == "udp" { + if ns.Type == UDPResolver { hub.Logger.Debug("initiating UDP resolver") rslvr, err := resolvers.NewUDPResolver(ns.Address, resolvers.UDPResolverOpts{ IPv4Only: hub.QueryFlags.UseIPv4, @@ -80,13 +84,13 @@ func getDefaultServers() ([]Nameserver, error) { // handle IPv6 if ip != nil && ip.To4() != nil { ns := Nameserver{ - Type: "udp", + Type: UDPResolver, Address: fmt.Sprintf("%s:%s", s, cfg.Port), } servers = append(servers, ns) } else { ns := Nameserver{ - Type: "udp", + Type: UDPResolver, Address: fmt.Sprintf("[%s]:%s", s, cfg.Port), } servers = append(servers, ns) @@ -98,7 +102,7 @@ func getDefaultServers() ([]Nameserver, error) { func initNameserver(n string) (Nameserver, error) { // Instantiate a dumb UDP resolver as a fallback. ns := Nameserver{ - Type: "udp", + Type: UDPResolver, Address: n, } u, err := url.Parse(n) @@ -106,19 +110,19 @@ func initNameserver(n string) (Nameserver, error) { return ns, err } if u.Scheme == "https" { + ns.Type = DOHResolver ns.Address = u.String() - ns.Type = "doh" } if u.Scheme == "tcp" { + ns.Type = TCPResolver if i := net.ParseIP(n); i != nil { // if no port specified in nameserver, append defaults. n = net.JoinHostPort(n, DefaultTLSPort) } ns.Address = u.String() - ns.Type = "tcp" } if u.Scheme == "udp" { - ns.Type = "udp" + ns.Type = UDPResolver if u.Port() == "" { ns.Address = net.JoinHostPort(u.Hostname(), DefaultUDPPort) } else {