0
0
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 13:21:00 +02:00

Add --internal-dns flag

This commit is contained in:
Charlie Jonas 2021-08-16 18:25:34 +01:00
parent b73fdff702
commit df2e29b74d
2 changed files with 13 additions and 8 deletions

View file

@ -80,6 +80,7 @@ func Run() (err error) {
}, },
} }
app.Flags = []cli.Flag{ 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: "remember", Usage: "save these settings to reuse next time"},
&cli.BoolFlag{Name: "debug", Usage: "toggle debug mode"}, &cli.BoolFlag{Name: "debug", Usage: "toggle debug mode"},
&cli.BoolFlag{Name: "yes", Usage: "automatically agree to all prompts"}, &cli.BoolFlag{Name: "yes", Usage: "automatically agree to all prompts"},

View file

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"net" "net"
"os"
"time" "time"
) )
@ -16,6 +17,7 @@ var (
DEFAULT_RELAY6 = "croc6.schollz.com" DEFAULT_RELAY6 = "croc6.schollz.com"
DEFAULT_PORT = "9009" DEFAULT_PORT = "9009"
DEFAULT_PASSPHRASE = "pass123" DEFAULT_PASSPHRASE = "pass123"
INTERNAL_DNS = false
) )
// lookupTimeout for DNS requests // lookupTimeout for DNS requests
@ -35,6 +37,13 @@ var publicDns = []string{
} }
func init() { func init() {
for _, flag := range os.Args {
if flag == "--internal-dns" {
INTERNAL_DNS = true
break
}
}
var err error var err error
DEFAULT_RELAY, err = lookup(DEFAULT_RELAY) DEFAULT_RELAY, err = lookup(DEFAULT_RELAY)
if err == nil { if err == nil {
@ -50,16 +59,11 @@ func init() {
} }
} }
// lookup an IP address. // Resolve a hostname to an IP address using DNS.
//
// Priority is given to local queries, and the system falls back to a list of
// public DNS servers.
func lookup(address string) (ipaddress string, err error) { func lookup(address string) (ipaddress string, err error) {
ipaddress, err = localLookupIP(address) if !INTERNAL_DNS {
if err == nil { return localLookupIP(address)
return
} }
err = nil
result := make(chan string, len(publicDns)) result := make(chan string, len(publicDns))
for _, dns := range publicDns { for _, dns := range publicDns {