Skip to content

Commit

Permalink
Add support for TTL (#117)
Browse files Browse the repository at this point in the history
* add support for TTL

* removing debug prog
  • Loading branch information
Mzack9999 committed Apr 26, 2023
1 parent ca94fa2 commit 3b2de2c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ func (c *Client) axfr(host string) (*AXFRData, error) {
// DNSData is the data for a DNS request response
type DNSData struct {
Host string `json:"host,omitempty"`
TTL int `json:"ttl,omitempty"`
TTL uint32 `json:"ttl,omitempty"`
Resolver []string `json:"resolver,omitempty"`
A []string `json:"a,omitempty"`
AAAA []string `json:"aaaa,omitempty"`
Expand Down Expand Up @@ -548,6 +548,9 @@ var CheckInternalIPs = false

func (d *DNSData) ParseFromRR(rrs []dns.RR) error {
for _, record := range rrs {
if d.TTL == 0 && record.Header().Ttl > 0 {
d.TTL = record.Header().Ttl
}
switch recordType := record.(type) {
case *dns.A:
if CheckInternalIPs && internalRangeCheckerInstance != nil && internalRangeCheckerInstance.ContainsIPv4(recordType.A) {
Expand Down
1 change: 1 addition & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func TestQueryMultiple(t *testing.T) {
// From current dig result
require.True(t, len(d.A) > 0)
require.True(t, len(d.AAAA) > 0)
require.NotZero(t, d.TTL)
}

func TestTrace(t *testing.T) {
Expand Down

0 comments on commit 3b2de2c

Please sign in to comment.