diff --git a/dnscrypt-proxy/config.go b/dnscrypt-proxy/config.go index fbfbed39..f609d9b8 100644 --- a/dnscrypt-proxy/config.go +++ b/dnscrypt-proxy/config.go @@ -104,6 +104,7 @@ type BlockIPConfig struct { func ConfigLoad(proxy *Proxy, svcFlag *string, config_file string) error { version := flag.Bool("version", false, "prints current proxy version") configFile := flag.String("config", "dnscrypt-proxy.toml", "path to the configuration file") + resolve := flag.String("resolve", "", "resolve a name using system libraries") flag.Parse() if *svcFlag == "stop" || *svcFlag == "uninstall" { return nil @@ -112,6 +113,10 @@ func ConfigLoad(proxy *Proxy, svcFlag *string, config_file string) error { fmt.Println(AppVersion) os.Exit(0) } + if resolve != nil && len(*resolve) > 0 { + Resolve(*resolve) + os.Exit(0) + } config := newConfig() if _, err := toml.DecodeFile(*configFile, &config); err != nil { return err diff --git a/dnscrypt-proxy/main.go b/dnscrypt-proxy/main.go index 8e9ac79d..1ea81411 100644 --- a/dnscrypt-proxy/main.go +++ b/dnscrypt-proxy/main.go @@ -60,7 +60,6 @@ type App struct { func main() { dlog.Init("dnscrypt-proxy", dlog.SeverityNotice, "DAEMON") - dlog.Noticef("Starting dnscrypt-proxy %s", AppVersion) cdLocal() @@ -80,6 +79,8 @@ func main() { if err := ConfigLoad(&app.proxy, svcFlag, "dnscrypt-proxy.toml"); err != nil { dlog.Fatal(err) } + dlog.Noticef("Starting dnscrypt-proxy %s", AppVersion) + if len(*svcFlag) != 0 { if err := service.Control(svc, *svcFlag); err != nil { dlog.Fatal(err) diff --git a/dnscrypt-proxy/resolve.go b/dnscrypt-proxy/resolve.go new file mode 100644 index 00000000..7d50b08c --- /dev/null +++ b/dnscrypt-proxy/resolve.go @@ -0,0 +1,60 @@ +package main + +import ( + "fmt" + "net" + "strings" +) + +const myResolverHost string = "resolver.dnscrypt.info" + +func Resolve(name string) { + fmt.Printf("Resolving [%s]\n\n", name) + + fmt.Printf("Domain exists: ") + ns, err := net.LookupNS(name) + if err != nil || len(ns) == 0 { + if name == "." { + fmt.Println("'No' would mean that the Internet doesn't exist any more, and that would be very sad. On the bright side, you just found an easter egg.") + } else { + fmt.Println("probably not, or blocked by the proxy") + } + } else { + fmt.Printf("yes, %d name servers found\n", len(ns)) + } + + fmt.Printf("Canonical name: ") + cname, err := net.LookupCNAME(name) + if err != nil { + fmt.Println("-") + } else { + fmt.Println(cname) + } + + fmt.Printf("IP addresses: ") + addrs, err := net.LookupHost(name) + if err != nil { + fmt.Println("-") + } else { + fmt.Println(strings.Join(addrs, ", ")) + } + + fmt.Printf("TXT records: ") + txt, err := net.LookupTXT(name) + if err != nil { + fmt.Println("-") + } else { + fmt.Println(strings.Join(txt, " ")) + } + + resIP, err := net.LookupHost(myResolverHost) + if err == nil && len(resIP) > 0 { + fmt.Printf("Resolver IP: %s", resIP[0]) + rev, err := net.LookupAddr(resIP[0]) + if err == nil && len(rev) > 0 { + fmt.Printf(" (%s)", rev[0]) + } + fmt.Println("") + } + fmt.Println("") +}