From f1e9f8bde3e0f6dc692eb1b39bc4a6df7b1836e3 Mon Sep 17 00:00:00 2001 From: Nate Sales Date: Wed, 13 Dec 2023 01:46:24 -0500 Subject: [PATCH] feat: round TTL flag --- README.md | 34 ++++++++++++---------------------- cli/cli.go | 1 + main.go | 9 +++++++++ 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 1e152ff..e544aa8 100644 --- a/README.md +++ b/README.md @@ -36,34 +36,28 @@ All long form (--) flags can be toggled with the dig-standard +[no]flag notation Application Options: -q, --qname= Query name -s, --server= DNS server(s) - -t, --type= RR type (e.g. A, AAAA, MX, etc.) or type - integer + -t, --type= RR type (e.g. A, AAAA, MX, etc.) or type integer -x, --reverse Reverse lookup -d, --dnssec Set the DO (DNSSEC OK) bit in the OPT record -n, --nsid Set EDNS0 NSID opt --subnet= Set EDNS0 client subnet -c, --chaos Use CHAOS query class - -C= Set query class (default: IN 0x01) (default: - 1) + -C= Set query class (default: IN 0x01) (default: 1) -p, --odoh-proxy= ODoH proxy --timeout= Query timeout (default: 10s) --pad Set EDNS0 padding --http3 Use HTTP/3 for DoH --id-check Check DNS response ID (default: true) - --reuse-conn Reuse connections across queries to the same - server (default: true) + --reuse-conn Reuse connections across queries to the same server (default: true) --txtconcat Concatenate TXT responses --qid= Set query ID (-1 for random) (default: -1) -b, --bootstrap-server= DNS server to use for bootstrapping --bootstrap-timeout= Bootstrapping timeout (default: 5s) --cookie= EDNS0 cookie --recaxfr Perform recursive AXFR - -f, --format= Output format (pretty, column, json, yaml, - raw) (default: pretty) - --pretty-ttls Format TTLs in human readable format - (default: true) - --short-ttls Remove zero components of pretty TTLs. - (24h0m0s->24h) (default: true) + -f, --format= Output format (pretty, column, json, yaml, raw) (default: pretty) + --pretty-ttls Format TTLs in human readable format (default: true) + --short-ttls Remove zero components of pretty TTLs. (24h0m0s->24h) (default: true) --color Enable color output --question Show question section --answer Show answer section (default: true) @@ -73,13 +67,12 @@ Application Options: --all Show all sections and statistics -w Resolve ASN/ASName for A and AAAA records -r, --short Show record values only - -R, --resolve-ips Resolve PTR records for IP addresses in A and - AAAA records + -R, --resolve-ips Resolve PTR records for IP addresses in A and AAAA records + --round-ttls Round TTLs to the nearest minute --aa Set AA (Authoritative Answer) flag in query --ad Set AD (Authentic Data) flag in query --cd Set CD (Checking Disabled) flag in query - --rd Set RD (Recursion Desired) flag in query - (default: true) + --rd Set RD (Recursion Desired) flag in query (default: true) --ra Set RA (Recursion Available) flag in query --z Set Z (Zero) flag in query --t Set TC (Truncated) flag in query @@ -97,15 +90,12 @@ Application Options: --http-method= HTTP method (default: GET) --pmtud PMTU discovery (default: true) --quic-alpn-tokens= QUIC ALPN tokens (default: doq, doq-i11) - --quic-length-prefix Add RFC 9250 compliant length prefix - (default: true) + --quic-length-prefix Add RFC 9250 compliant length prefix (default: true) --dnscrypt-tcp Use TCP for DNSCrypt (default UDP) - --dnscrypt-udp-size= Maximum size of a DNS response this client - can sent or receive (default: 0) + --dnscrypt-udp-size= Maximum size of a DNS response this client can sent or receive (default: 0) --dnscrypt-key= DNSCrypt public key --dnscrypt-provider= DNSCrypt provider name - --default-rr-types= Default record types (default: A, AAAA, NS, - MX, TXT, CNAME) + --default-rr-types= Default record types (default: A, AAAA, NS, MX, TXT, CNAME) --udp-buffer= Set EDNS0 UDP size in query (default: 1232) -v, --verbose Show verbose log messages --trace Show trace log messages diff --git a/cli/cli.go b/cli/cli.go index a0ad3b1..3fc7406 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -50,6 +50,7 @@ type Flags struct { Whois bool `short:"w" description:"Resolve ASN/ASName for A and AAAA records"` ValueOnly bool `short:"r" long:"short" description:"Show record values only"` ResolveIPs bool `short:"R" long:"resolve-ips" description:"Resolve PTR records for IP addresses in A and AAAA records"` + RoundTTLs bool `long:"round-ttls" description:"Round TTLs to the nearest minute"` // Header flags AuthoritativeAnswer bool `long:"aa" description:"Set AA (Authoritative Answer) flag in query"` diff --git a/main.go b/main.go index df6bb83..553961a 100644 --- a/main.go +++ b/main.go @@ -449,6 +449,15 @@ All long form (--) flags can be toggled with the dig-standard +[no]flag notation } } + // Round TTL + if opts.RoundTTLs { + for _, reply := range replies { + for _, rr := range reply.Answer { + rr.Header().Ttl = rr.Header().Ttl - (rr.Header().Ttl % 60) + } + } + } + entries = append(entries, &output.Entry{ Queries: msgs, Replies: replies,