Skip to content

Commit

Permalink
chore: added support for all type of dns record
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmoysrt committed Nov 22, 2023
1 parent 58afd5b commit 3f99d77
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 12 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,14 @@ import (

func parseQuery(m *dns.Msg, qdns *QuickDNSResolver) {
for _, q := range m.Question {
println(q.Name, q.Qtype)
println("Query: ", q.Name, q.Qtype, q.Qclass)
switch q.Qtype {
case dns.TypeNone:
fallthrough
case dns.TypeANY:
fallthrough
case dns.TypeNS:
fallthrough
case dns.TypeA:
{
isQDNS, ip := qdns.ResolveARecord(q.Name)
if isQDNS {
rr, err := dns.NewRR(fmt.Sprintf("%s A %s", q.Name, ip))
if err == nil {
m.Answer = append(m.Answer, rr)
}
}
// ns1.swiftwave.xyz and ns2.swiftwave.xyz
rr, err := dns.NewRR(fmt.Sprintf("%s NS ns1.swiftwave.xyz", q.Name))
if err == nil {
Expand All @@ -37,6 +28,16 @@ func parseQuery(m *dns.Msg, qdns *QuickDNSResolver) {
m.Answer = append(m.Answer, rr)
}
}
case dns.TypeA:
{
isQDNS, ip := qdns.ResolveARecord(q.Name)
if isQDNS {
rr, err := dns.NewRR(fmt.Sprintf("%s A %s", q.Name, ip))
if err == nil {
m.Answer = append(m.Answer, rr)
}
}
}
}
}
}
Expand All @@ -59,7 +60,7 @@ func main() {
panic(err)
}
// attach request handler func
dns.HandleFunc("swiftwave.xyz", func(w dns.ResponseWriter, m *dns.Msg) {
dns.HandleFunc(".", func(w dns.ResponseWriter, m *dns.Msg) {
handleDnsRequest(w, m, qdns)
})
// start server
Expand Down
2 changes: 2 additions & 0 deletions quickdns_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"regexp"
"strings"
)

/**
Expand Down Expand Up @@ -31,6 +32,7 @@ func NewQuickDNSResolver() (*QuickDNSResolver, error) {
// Returns true if the domain name is in the format ip-3-56-23-12.swiftwave.xyz
// Also returns the IP address
func (q *QuickDNSResolver) ResolveARecord(domain string) (bool, string) {
domain = strings.ToLower(domain)
if matches := q.Regex.FindStringSubmatch(domain); len(matches) == 5 {
ip := fmt.Sprintf("%s.%s.%s.%s", matches[1], matches[2], matches[3], matches[4])
return true, ip
Expand Down

0 comments on commit 3f99d77

Please sign in to comment.