Created
July 23, 2020 10:10
-
-
Save ghedo/cdb98af5df6a8a2bf97aac6a06ab27aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
import "net" | |
import "sync" | |
import "strings" | |
import "github.com/miekg/dns" | |
func handleRequest(w dns.ResponseWriter, r *dns.Msg) { | |
fmt.Println(r) | |
m := new(dns.Msg) | |
m.SetReply(r) | |
switch strings.ToLower(r.Question[0].Name) { | |
case "ns1.nullroute.dev.", "ns2.nullroute.dev.": | |
a := &dns.A{ | |
Hdr: dns.RR_Header{ | |
Name: r.Question[0].Name, | |
Rrtype: dns.TypeA, | |
Class: dns.ClassINET, | |
Ttl: 300, | |
}, | |
A: net.IPv4(45, 77, 96, 66), | |
} | |
m.Answer = append(m.Answer, a) | |
case "nullroute.dev.": | |
svcb := &dns.SVCB{ | |
Hdr: dns.RR_Header{ | |
Name: r.Question[0].Name, | |
Rrtype: dns.TypeHTTPS, | |
Class: dns.ClassINET, | |
Ttl: 300, | |
}, | |
Priority: 1, | |
Target: ".", | |
Value: []dns.SVCBKeyValue{ | |
&dns.SVCBAlpn{ | |
Alpn: []string{"h2", "h3"}, | |
}, | |
&dns.SVCBIPv4Hint{ | |
Hint: []net.IP{net.IPv4(45, 77, 96, 66)}, | |
}, | |
}, | |
} | |
m.Answer = append(m.Answer, svcb) | |
a := &dns.A { | |
Hdr: dns.RR_Header{ | |
Name: r.Question[0].Name, | |
Rrtype: dns.TypeA, | |
Class: dns.ClassINET, | |
Ttl: 300, | |
}, | |
/* A: net.IPv4(45, 77, 96, 66), */ | |
A: net.IPv4(198, 51, 100, 1), | |
} | |
m.Extra = append(m.Extra, a) | |
} | |
err := w.WriteMsg(m) | |
if err != nil { | |
fmt.Println(err) | |
} | |
} | |
func main() { | |
var wg sync.WaitGroup | |
wg.Add(1) | |
dns.HandleFunc("nullroute.dev.", handleRequest) | |
server := &dns.Server{Addr: ":53", Net: "udp"} | |
go server.ListenAndServe() | |
wg.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment