Skip to content

Commit

Permalink
Add SRV support (#71)
Browse files Browse the repository at this point in the history
* Add SRV support

* Add SRV support
  • Loading branch information
edoardottt authored Oct 20, 2022
1 parent e2b34ab commit 6856cef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func main() {
log.Println(ips)

// Query Types: dns.TypeA, dns.TypeNS, dns.TypeCNAME, dns.TypeSOA, dns.TypePTR, dns.TypeMX
// dns.TypeTXT, dns.TypeAAAA (from github.com/miekg/dns)
// dns.TypeTXT, dns.TypeAAAA, dns.TypeSRV (from github.com/miekg/dns)
dnsResponses, err := dnsClient.Query(hostname, dns.TypeA)
if err != nil {
log.Fatal(err)
Expand Down
11 changes: 10 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ func (c *Client) TXT(host string) (*DNSData, error) {
return c.QueryMultiple(host, []uint16{dns.TypeTXT})
}

// SRV helper function
func (c *Client) SRV(host string) (*DNSData, error) {
return c.QueryMultiple(host, []uint16{dns.TypeSRV})
}

// PTR helper function
func (c *Client) PTR(host string) (*DNSData, error) {
return c.QueryMultiple(host, []uint16{dns.TypePTR})
Expand Down Expand Up @@ -521,6 +526,7 @@ type DNSData struct {
SOA []string `json:"soa,omitempty"`
NS []string `json:"ns,omitempty"`
TXT []string `json:"txt,omitempty"`
SRV []string `json:"srv,omitempty"`
CAA []string `json:"caa,omitempty"`
AllRecords []string `json:"all,omitempty"`
Raw string `json:"raw,omitempty"`
Expand Down Expand Up @@ -565,6 +571,8 @@ func (d *DNSData) ParseFromRR(rrs []dns.RR) error {
for _, txt := range recordType.Txt {
d.TXT = append(d.TXT, trimChars(txt))
}
case *dns.SRV:
d.SRV = append(d.SRV, trimChars(recordType.Target))
case *dns.AAAA:
if CheckInternalIPs && internalRangeCheckerInstance.ContainsIPv6(recordType.AAAA) {
d.HasInternalIPs = true
Expand Down Expand Up @@ -596,7 +604,7 @@ func (d *DNSData) ParseFromEnvelopeChan(envChan chan *dns.Envelope) error {
}

func (d *DNSData) contains() bool {
return len(d.A) > 0 || len(d.AAAA) > 0 || len(d.CNAME) > 0 || len(d.MX) > 0 || len(d.NS) > 0 || len(d.PTR) > 0 || len(d.TXT) > 0 || len(d.SOA) > 0 || len(d.CAA) > 0
return len(d.A) > 0 || len(d.AAAA) > 0 || len(d.CNAME) > 0 || len(d.MX) > 0 || len(d.NS) > 0 || len(d.PTR) > 0 || len(d.TXT) > 0 || len(d.SRV) > 0 || len(d.SOA) > 0 || len(d.CAA) > 0
}

// JSON returns the object as json string
Expand All @@ -619,6 +627,7 @@ func (d *DNSData) dedupe() {
d.SOA = sliceutil.Dedupe(d.SOA)
d.NS = sliceutil.Dedupe(d.NS)
d.TXT = sliceutil.Dedupe(d.TXT)
d.SRV = sliceutil.Dedupe(d.SRV)
d.CAA = sliceutil.Dedupe(d.CAA)
d.AllRecords = sliceutil.Dedupe(d.AllRecords)
}
Expand Down

0 comments on commit 6856cef

Please sign in to comment.