2020-12-09 18:11:09 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-12-13 13:19:10 +01:00
|
|
|
"fmt"
|
2020-12-09 18:11:09 +01:00
|
|
|
"os"
|
|
|
|
|
2020-12-13 13:19:10 +01:00
|
|
|
"github.com/knadh/koanf"
|
|
|
|
"github.com/knadh/koanf/providers/posflag"
|
|
|
|
flag "github.com/spf13/pflag"
|
2020-12-09 18:11:09 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// Version and date of the build. This is injected at build-time.
|
2020-12-13 08:15:45 +01:00
|
|
|
buildVersion = "unknown"
|
|
|
|
buildDate = "unknown"
|
2020-12-13 13:19:10 +01:00
|
|
|
k = koanf.New(".")
|
2020-12-09 18:11:09 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2020-12-10 10:39:05 +01:00
|
|
|
var (
|
2020-12-13 08:15:45 +01:00
|
|
|
logger = initLogger()
|
2020-12-10 10:39:05 +01:00
|
|
|
)
|
2020-12-13 13:19:10 +01:00
|
|
|
|
2020-12-10 10:39:05 +01:00
|
|
|
// Initialize hub.
|
|
|
|
hub := NewHub(logger, buildVersion)
|
2020-12-10 17:14:04 +01:00
|
|
|
|
2020-12-13 13:19:10 +01:00
|
|
|
// Configure Flags
|
|
|
|
// Use the POSIX compliant pflag lib instead of Go's flag lib.
|
|
|
|
f := flag.NewFlagSet("config", flag.ContinueOnError)
|
|
|
|
f.Usage = func() {
|
|
|
|
fmt.Println(f.FlagUsages())
|
|
|
|
os.Exit(0)
|
2020-12-09 18:11:09 +01:00
|
|
|
}
|
2020-12-13 13:19:10 +01:00
|
|
|
// Path to one or more config files to load into koanf along with some config params.
|
|
|
|
f.StringSliceP("query", "q", []string{}, "Domain name to query")
|
|
|
|
f.StringSliceP("type", "t", []string{}, "Type of DNS record to be queried (A, AAAA, MX etc)")
|
|
|
|
f.StringSliceP("class", "c", []string{}, "Network class of the DNS record to be queried (IN, CH, HS etc)")
|
|
|
|
f.StringSliceP("nameservers", "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.Bool("search", false, "Use the search list provided in resolv.conf. It sets the `ndots` parameter as well unless overriden by `ndots` flag.")
|
|
|
|
f.Int("ndots", 1, "Specify the ndots paramter")
|
|
|
|
|
|
|
|
// Output Options
|
|
|
|
f.BoolP("json", "J", false, "Set the output format as JSON")
|
|
|
|
f.Bool("time", false, "Display how long it took for the response to arrive")
|
|
|
|
f.Bool("debug", false, "Enable debug mode")
|
|
|
|
|
|
|
|
// Parse and Load Flags
|
|
|
|
f.Parse(os.Args[1:])
|
|
|
|
if err := k.Load(posflag.Provider(f, ".", k), nil); err != nil {
|
|
|
|
hub.Logger.Fatalf("error loading flags: %v", err)
|
|
|
|
fmt.Println(f.FlagUsages())
|
|
|
|
os.Exit(0)
|
2020-12-09 18:11:09 +01:00
|
|
|
}
|
2020-12-13 08:15:45 +01:00
|
|
|
|
2020-12-09 18:11:09 +01:00
|
|
|
// Run the app.
|
2020-12-10 17:14:04 +01:00
|
|
|
hub.Logger.Debug("Starting doggo...")
|
2020-12-13 13:19:10 +01:00
|
|
|
|
|
|
|
// Parse Query Args
|
|
|
|
hub.loadQueryArgs()
|
|
|
|
|
|
|
|
// Start App
|
|
|
|
if len(hub.QueryFlags.QNames) == 0 {
|
|
|
|
fmt.Println(f.FlagUsages())
|
|
|
|
os.Exit(0)
|
2020-12-09 18:11:09 +01:00
|
|
|
}
|
2020-12-13 13:19:10 +01:00
|
|
|
hub.Lookup()
|
|
|
|
|
2020-12-09 18:11:09 +01:00
|
|
|
}
|