-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (61 loc) · 1.35 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"github.com/miekg/dns"
"github.com/shemul/dns-over-tls/config"
"github.com/shemul/dns-over-tls/handler"
"github.com/urfave/cli"
"log"
"os"
"time"
)
var (
App = cli.NewApp()
)
//var serverTcp *dns.Server
func main() {
conf := config.Config{
//Cloudflare's dns as resolver
UpStreamResolverIp: "1.1.1.1",
UpStreamResolverPort: "853",
TCPPort: ":53",
UPDPort: ":53",
UpstreamTimeout: time.Millisecond * 3000,
}
dns.HandleFunc(".", handler.DNSHandler(conf))
App.Name = "DNS-over-TLS Proxy over Cloudflare upstream"
App.UsageText = "ex: go run main.go udp"
App.Commands = []cli.Command{
{
Name: "udp",
Usage: "run the UDP/53 server",
Action: func(c *cli.Context) {
udp := dns.Server{Addr: conf.UPDPort, Net: "udp"}
StartServer(&udp)
},
},
{
Name: "tcp",
Usage: "run the TCP/53 server",
Action: func(c *cli.Context) {
udp := dns.Server{Addr: conf.UPDPort, Net: "tcp"}
StartServer(&udp)
},
},
}
err := App.Run(os.Args)
if err != nil {
panic(err.Error())
}
}
func StartServer(s *dns.Server) {
log.Printf("DNS server is running on port %v/%v", s.Net, s.Addr)
n := ""
if s.Net == "tcp" {
n = "+tcp"
}
log.Printf("try in cli : dig +short %v google.com @localhost", n)
err := s.ListenAndServe()
if err != nil {
panic(err.Error())
}
}