SHA256
Can do all with one argument, and includes start and end timestamps.
This commit is contained in:
+21
-10
@@ -4,6 +4,7 @@ import argparse
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
from datetime import datetime
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from dns import message
|
from dns import message
|
||||||
from dns import query
|
from dns import query
|
||||||
@@ -28,7 +29,7 @@ builtin_nameservers = {
|
|||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--domain', help='Helps if all records to query are on the same domain.')
|
parser.add_argument('--domain', help='Helps if all records to query are on the same domain.')
|
||||||
parser.add_argument('--nameservers', nargs='+', help='IPv4 or IPv6 address of nameserver(s) to be queried.')
|
parser.add_argument('--nameservers', nargs='+', help='IPv4 or IPv6 address of nameserver(s) to be queried.')
|
||||||
parser.add_argument('--ns-builtin', nargs='+', help=f'Built-in public DNS servers. Options: {", ".join(builtin_nameservers.keys())}')
|
parser.add_argument('--ns-builtin', nargs='+', help=f'Built-in public DNS servers. Options: {", ".join(builtin_nameservers.keys())}, all')
|
||||||
parser.add_argument('--records', nargs='*', help='Hostname(s) to query. If not provided with --domain, queries the domain itself.')
|
parser.add_argument('--records', nargs='*', help='Hostname(s) to query. If not provided with --domain, queries the domain itself.')
|
||||||
parser.add_argument('--record-type', default='A', help='DNS record type to query. Default: A')
|
parser.add_argument('--record-type', default='A', help='DNS record type to query. Default: A')
|
||||||
parser.add_argument('--list-record-types', action='store_true', help='Print list of supported record types and exit.')
|
parser.add_argument('--list-record-types', action='store_true', help='Print list of supported record types and exit.')
|
||||||
@@ -40,15 +41,19 @@ builtin_providers = [] # list of provider keys used
|
|||||||
|
|
||||||
# Resolve builtin nameservers to actual IPs
|
# Resolve builtin nameservers to actual IPs
|
||||||
if args.ns_builtin:
|
if args.ns_builtin:
|
||||||
for provider in args.ns_builtin:
|
# Handle 'all' special case
|
||||||
if provider.lower() not in builtin_nameservers:
|
if 'all' in [p.lower() for p in args.ns_builtin]:
|
||||||
|
builtin_providers = list(builtin_nameservers.keys())
|
||||||
|
else:
|
||||||
|
builtin_providers = [p.lower() for p in args.ns_builtin]
|
||||||
|
|
||||||
|
for provider in builtin_providers:
|
||||||
|
if provider not in builtin_nameservers:
|
||||||
print(f"Error: Unknown DNS provider '{provider}'")
|
print(f"Error: Unknown DNS provider '{provider}'")
|
||||||
print(f"Available providers: {', '.join(builtin_nameservers.keys())}")
|
print(f"Available providers: {', '.join(builtin_nameservers.keys())}, all")
|
||||||
exit(1)
|
exit(1)
|
||||||
provider_key = provider.lower()
|
for ip in builtin_nameservers[provider]:
|
||||||
builtin_providers.append(provider_key)
|
nameserver_map[ip] = provider
|
||||||
for ip in builtin_nameservers[provider_key]:
|
|
||||||
nameserver_map[ip] = provider_key
|
|
||||||
|
|
||||||
# Track manual nameservers separately
|
# Track manual nameservers separately
|
||||||
manual_nameservers = []
|
manual_nameservers = []
|
||||||
@@ -101,6 +106,7 @@ def perform_query(full_domain, ns, record_type):
|
|||||||
|
|
||||||
# Start timer
|
# Start timer
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
start_time_iso = datetime.fromtimestamp(start_time).isoformat()
|
||||||
|
|
||||||
# Determine what to query
|
# Determine what to query
|
||||||
if args.domain:
|
if args.domain:
|
||||||
@@ -171,8 +177,13 @@ for full_domain in full_domains:
|
|||||||
if (full_domain, ns) in results_map:
|
if (full_domain, ns) in results_map:
|
||||||
output[full_domain]["records"][ns] = results_map[(full_domain, ns)]
|
output[full_domain]["records"][ns] = results_map[(full_domain, ns)]
|
||||||
|
|
||||||
# Calculate and add runtime
|
# Calculate and add timing information
|
||||||
elapsed_time = time.time() - start_time
|
end_time = time.time()
|
||||||
|
end_time_iso = datetime.fromtimestamp(end_time).isoformat()
|
||||||
|
elapsed_time = end_time - start_time
|
||||||
|
|
||||||
|
output["start_time"] = start_time_iso
|
||||||
|
output["end_time"] = end_time_iso
|
||||||
output["runtime"] = f"{elapsed_time:.2f}s"
|
output["runtime"] = f"{elapsed_time:.2f}s"
|
||||||
|
|
||||||
print(json.dumps(output, indent=4))
|
print(json.dumps(output, indent=4))
|
||||||
|
|||||||
Reference in New Issue
Block a user