diff --git a/src/cli/cli.go b/src/cli/cli.go index 1808cb21..8dcadc62 100644 --- a/src/cli/cli.go +++ b/src/cli/cli.go @@ -80,6 +80,7 @@ func Run() (err error) { }, } app.Flags = []cli.Flag{ + &cli.BoolFlag{Name: "internal-dns", Usage: "use a built-in DNS stub resolver rather than the host operating system"}, &cli.BoolFlag{Name: "remember", Usage: "save these settings to reuse next time"}, &cli.BoolFlag{Name: "debug", Usage: "toggle debug mode"}, &cli.BoolFlag{Name: "yes", Usage: "automatically agree to all prompts"}, diff --git a/src/models/constants.go b/src/models/constants.go index 183d0b28..66c5ca63 100644 --- a/src/models/constants.go +++ b/src/models/constants.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "net" + "os" "time" ) @@ -16,6 +17,7 @@ var ( DEFAULT_RELAY6 = "croc6.schollz.com" DEFAULT_PORT = "9009" DEFAULT_PASSPHRASE = "pass123" + INTERNAL_DNS = false ) // lookupTimeout for DNS requests @@ -35,6 +37,13 @@ var publicDns = []string{ } func init() { + for _, flag := range os.Args { + if flag == "--internal-dns" { + INTERNAL_DNS = true + break + } + } + var err error DEFAULT_RELAY, err = lookup(DEFAULT_RELAY) if err == nil { @@ -50,16 +59,11 @@ func init() { } } -// lookup an IP address. -// -// Priority is given to local queries, and the system falls back to a list of -// public DNS servers. +// Resolve a hostname to an IP address using DNS. func lookup(address string) (ipaddress string, err error) { - ipaddress, err = localLookupIP(address) - if err == nil { - return + if !INTERNAL_DNS { + return localLookupIP(address) } - err = nil result := make(chan string, len(publicDns)) for _, dns := range publicDns {