Premium Only Content
Create your own DNS response time tool in Python
I can’t count the number of times I wish I had a tool that just …….
Many times, the tool exists, but part of a network management suite or solution which is not practical to install and configure for a simple test or the odd troubleshooting task.
In this video I will show you a small piece of code that I wrote to record DNS response time.
Here is the code below for you to simply cut and paste.
import csv
import datetime
import time
import dns.resolver
# DNS name to resolve
domain_name = "thetechfirm.com"
# Number of times to measure DNS response time
num_measurements = 100
counter = 0
delay = 1
print("Tonys DNS response time utility")
print("Performing name lookups for", domain_name, num_measurements, "times with a ", delay, "second delay")
# Create CSV file and write header row
with open('dns_response_times.csv', mode='w') as csv_file:
fieldnames = ['Date', 'Response Time (ms)']
writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
writer.writeheader()
# Measure DNS response time multiple times and write results to CSV file
for i in range(num_measurements):
counter = counter+1
start_time = time.time()
# Perform DNS resolution
resolver = dns.resolver.Resolver()
resolver.nameservers = ['8.8.8.8'] # Google DNS server
answer = dns.resolver.resolve(domain_name)
end_time = time.time()
response_time_ms = (end_time - start_time) * 1000
# Write result to CSV file
writer.writerow({'Date': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), 'Response Time (ms)': response_time_ms})
print("Testing", domain_name, "#", counter,response_time_ms,"ms")
time.sleep(delay)
-
21:33
Degenerate Jay
1 day agoThe Best Video Game Movie Ever Made? Sonic The Hedgehog 3 Movie Review
317 -
19:57
BlackDiamondGunsandGear
3 days agoIS 22LR ENOUGH?
13 -
1:59:47
Anthony Rogers
15 hours agoLIVE Comedy @ Cusumano's Pizza (Upstairs)
196 -
5:02:46
MoFio23!
13 hours agoNintendo Switch It UP Saturdays with The Fellas: LIVE - Episode #1
69.3K13 -
4:26:49
BLoobsGaming
13 hours agoCan I get an Enhance Crystal Weapon Seed please!? MORE Corrupted Gauntlet
126K42 -
7:35:05
BSparksGaming
1 day agoDynamic Duo! Marvel Rivals w/ Chili XDD
79.6K -
7:00:42
NellieBean
15 hours ago🔴 LIVE - trying some COD maybe Pals later
81K1 -
1:47:46
SpartakusLIVE
13 hours agoThe Master RIZZLER has entered the building, the 95% REJOICE
35.4K3 -
29:53
MYLUNCHBREAK CHANNEL PAGE
1 day agoOff Limits to the Public - Pt 1
97.5K175 -
16:03
Tundra Tactical
15 hours ago $20.11 earnedNew Age Gun Fudds
149K20