Skip to content

Commit 05e07e8

Browse files
committed
Add a simple built-in DNS client for testing
1 parent d9b5625 commit 05e07e8

3 files changed

Lines changed: 67 additions & 1 deletion

File tree

dnscrypt-proxy/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ type BlockIPConfig struct {
104104
func ConfigLoad(proxy *Proxy, svcFlag *string, config_file string) error {
105105
version := flag.Bool("version", false, "prints current proxy version")
106106
configFile := flag.String("config", "dnscrypt-proxy.toml", "path to the configuration file")
107+
resolve := flag.String("resolve", "", "resolve a name using system libraries")
107108
flag.Parse()
108109
if *svcFlag == "stop" || *svcFlag == "uninstall" {
109110
return nil
@@ -112,6 +113,10 @@ func ConfigLoad(proxy *Proxy, svcFlag *string, config_file string) error {
112113
fmt.Println(AppVersion)
113114
os.Exit(0)
114115
}
116+
if resolve != nil && len(*resolve) > 0 {
117+
Resolve(*resolve)
118+
os.Exit(0)
119+
}
115120
config := newConfig()
116121
if _, err := toml.DecodeFile(*configFile, &config); err != nil {
117122
return err

dnscrypt-proxy/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ type App struct {
6060

6161
func main() {
6262
dlog.Init("dnscrypt-proxy", dlog.SeverityNotice, "DAEMON")
63-
dlog.Noticef("Starting dnscrypt-proxy %s", AppVersion)
6463

6564
cdLocal()
6665

@@ -80,6 +79,8 @@ func main() {
8079
if err := ConfigLoad(&app.proxy, svcFlag, "dnscrypt-proxy.toml"); err != nil {
8180
dlog.Fatal(err)
8281
}
82+
dlog.Noticef("Starting dnscrypt-proxy %s", AppVersion)
83+
8384
if len(*svcFlag) != 0 {
8485
if err := service.Control(svc, *svcFlag); err != nil {
8586
dlog.Fatal(err)

dnscrypt-proxy/resolve.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"net"
6+
"strings"
7+
)
8+
9+
const myResolverHost string = "resolver.dnscrypt.info"
10+
11+
func Resolve(name string) {
12+
fmt.Printf("Resolving [%s]\n\n", name)
13+
14+
fmt.Printf("Domain exists: ")
15+
ns, err := net.LookupNS(name)
16+
if err != nil || len(ns) == 0 {
17+
if name == "." {
18+
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.")
19+
} else {
20+
fmt.Println("probably not, or blocked by the proxy")
21+
}
22+
} else {
23+
fmt.Printf("yes, %d name servers found\n", len(ns))
24+
}
25+
26+
fmt.Printf("Canonical name: ")
27+
cname, err := net.LookupCNAME(name)
28+
if err != nil {
29+
fmt.Println("-")
30+
} else {
31+
fmt.Println(cname)
32+
}
33+
34+
fmt.Printf("IP addresses: ")
35+
addrs, err := net.LookupHost(name)
36+
if err != nil {
37+
fmt.Println("-")
38+
} else {
39+
fmt.Println(strings.Join(addrs, ", "))
40+
}
41+
42+
fmt.Printf("TXT records: ")
43+
txt, err := net.LookupTXT(name)
44+
if err != nil {
45+
fmt.Println("-")
46+
} else {
47+
fmt.Println(strings.Join(txt, " "))
48+
}
49+
50+
resIP, err := net.LookupHost(myResolverHost)
51+
if err == nil && len(resIP) > 0 {
52+
fmt.Printf("Resolver IP: %s", resIP[0])
53+
rev, err := net.LookupAddr(resIP[0])
54+
if err == nil && len(rev) > 0 {
55+
fmt.Printf(" (%s)", rev[0])
56+
}
57+
fmt.Println("")
58+
}
59+
fmt.Println("")
60+
}

0 commit comments

Comments
 (0)