Add a simple built-in DNS client for testing
This commit is contained in:
parent
d9b5625226
commit
05e07e8b69
|
@ -104,6 +104,7 @@ type BlockIPConfig struct {
|
||||||
func ConfigLoad(proxy *Proxy, svcFlag *string, config_file string) error {
|
func ConfigLoad(proxy *Proxy, svcFlag *string, config_file string) error {
|
||||||
version := flag.Bool("version", false, "prints current proxy version")
|
version := flag.Bool("version", false, "prints current proxy version")
|
||||||
configFile := flag.String("config", "dnscrypt-proxy.toml", "path to the configuration file")
|
configFile := flag.String("config", "dnscrypt-proxy.toml", "path to the configuration file")
|
||||||
|
resolve := flag.String("resolve", "", "resolve a name using system libraries")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if *svcFlag == "stop" || *svcFlag == "uninstall" {
|
if *svcFlag == "stop" || *svcFlag == "uninstall" {
|
||||||
return nil
|
return nil
|
||||||
|
@ -112,6 +113,10 @@ func ConfigLoad(proxy *Proxy, svcFlag *string, config_file string) error {
|
||||||
fmt.Println(AppVersion)
|
fmt.Println(AppVersion)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
if resolve != nil && len(*resolve) > 0 {
|
||||||
|
Resolve(*resolve)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
config := newConfig()
|
config := newConfig()
|
||||||
if _, err := toml.DecodeFile(*configFile, &config); err != nil {
|
if _, err := toml.DecodeFile(*configFile, &config); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -60,7 +60,6 @@ type App struct {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
dlog.Init("dnscrypt-proxy", dlog.SeverityNotice, "DAEMON")
|
dlog.Init("dnscrypt-proxy", dlog.SeverityNotice, "DAEMON")
|
||||||
dlog.Noticef("Starting dnscrypt-proxy %s", AppVersion)
|
|
||||||
|
|
||||||
cdLocal()
|
cdLocal()
|
||||||
|
|
||||||
|
@ -80,6 +79,8 @@ func main() {
|
||||||
if err := ConfigLoad(&app.proxy, svcFlag, "dnscrypt-proxy.toml"); err != nil {
|
if err := ConfigLoad(&app.proxy, svcFlag, "dnscrypt-proxy.toml"); err != nil {
|
||||||
dlog.Fatal(err)
|
dlog.Fatal(err)
|
||||||
}
|
}
|
||||||
|
dlog.Noticef("Starting dnscrypt-proxy %s", AppVersion)
|
||||||
|
|
||||||
if len(*svcFlag) != 0 {
|
if len(*svcFlag) != 0 {
|
||||||
if err := service.Control(svc, *svcFlag); err != nil {
|
if err := service.Control(svc, *svcFlag); err != nil {
|
||||||
dlog.Fatal(err)
|
dlog.Fatal(err)
|
||||||
|
|
|
@ -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("")
|
||||||
|
}
|
Loading…
Reference in New Issue