Skip to content

Commit

Permalink
Merge pull request #127 from Sekost/main
Browse files Browse the repository at this point in the history
add SOA support
  • Loading branch information
Mzack9999 authored May 22, 2023
2 parents c6b8b7e + abcbbd7 commit 06c1c66
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
22 changes: 18 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ type DNSData struct {
MX []string `json:"mx,omitempty"`
PTR []string `json:"ptr,omitempty"`
ANY []string `json:"any,omitempty"`
SOA []string `json:"soa,omitempty"`
SOA []SOA `json:"soa,omitempty"`
NS []string `json:"ns,omitempty"`
TXT []string `json:"txt,omitempty"`
SRV []string `json:"srv,omitempty"`
Expand All @@ -548,6 +548,15 @@ type DNSData struct {
HostsFile bool `json:"hosts_file,omitempty"`
}

type SOA struct {
Name string `json:"name,omitempty"`
Serial uint32 `json:"serial,omitempty"`
Refresh uint32 `json:"refresh,omitempty"`
Retry uint32 `json:"retry,omitempty"`
Expire uint32 `json:"expire,omitempty"`
Minttl uint32 `json:"minttl,omitempty"`
}

// CheckInternalIPs when set to true returns if DNS response IPs
// belong to internal IP ranges.
var CheckInternalIPs = false
Expand All @@ -569,8 +578,14 @@ func (d *DNSData) ParseFromRR(rrs []dns.RR) error {
case *dns.CNAME:
d.CNAME = append(d.CNAME, trimChars(recordType.Target))
case *dns.SOA:
d.SOA = append(d.SOA, trimChars(recordType.Ns))
d.SOA = append(d.SOA, trimChars(recordType.Mbox))
d.SOA = append(d.SOA, SOA{
Name: recordType.Hdr.Name,
Serial: recordType.Serial,
Refresh: recordType.Refresh,
Retry: recordType.Retry,
Expire: recordType.Expire,
Minttl: recordType.Minttl,
})
case *dns.PTR:
d.PTR = append(d.PTR, trimChars(recordType.Ptr))
case *dns.MX:
Expand Down Expand Up @@ -635,7 +650,6 @@ func (d *DNSData) dedupe() {
d.MX = sliceutil.Dedupe(d.MX)
d.PTR = sliceutil.Dedupe(d.PTR)
d.ANY = sliceutil.Dedupe(d.ANY)
d.SOA = sliceutil.Dedupe(d.SOA)
d.NS = sliceutil.Dedupe(d.NS)
d.TXT = sliceutil.Dedupe(d.TXT)
d.SRV = sliceutil.Dedupe(d.SRV)
Expand Down
8 changes: 7 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,18 @@ func TestDOT(t *testing.T) {
func TestQueryMultiple(t *testing.T) {
client, _ := New([]string{"8.8.8.8:53", "1.1.1.1:53"}, 5)

d, err := client.QueryMultiple("example.com", []uint16{dns.TypeA, dns.TypeAAAA})
// Test various query types
d, err := client.QueryMultiple("scanme.sh", []uint16{
dns.TypeA,
dns.TypeAAAA,
dns.TypeSOA,
})
require.Nil(t, err)

// From current dig result
require.True(t, len(d.A) > 0)
require.True(t, len(d.AAAA) > 0)
require.True(t, len(d.SOA) > 0)
require.NotZero(t, d.TTL)
}

Expand Down

0 comments on commit 06c1c66

Please sign in to comment.