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)
-
5:09
Guns & Gadgets 2nd Amendment News
20 hours agoFBI Stops 9/11 Style Terror Attack!!
3.47K6 -
9:39
GBGunsRumble
21 hours agoGBGuns Armory Ep 128 Kimber R7 Mako Carbon Compact
39.8K8 -
1:00:51
The Tom Renz Show
19 hours ago"DEI Is Racist - Who knew & Redfield Now Worries About COVID Jabs"
38.6K5 -
5:01
BIG NEM
11 hours agoInside the Albanian Mob... As a Serb.
17.1K2 -
1:40:14
TheConnieBryanShow
4 days agoGAIN OF FUNCTION: MRNA, D.A.R.P.A. & THE PFIZER PAPERS
15.6K4 -
2:14:01
Fresh and Fit
8 hours agoDr. Disrespect Moves To Rumble!
66.4K33 -
6:14:53
Akademiks
11 hours agoDrake Sued his Label for Botting Kendrick Lamar Streams to 'End Him'. Kendrick Drops new video!
74.8K18 -
0:46
Dr Disrespect
16 hours agoIt's not just a stream... it's an experience
342K1.78K -
5:45:38
80sKiid
11 hours ago $29.20 earnedFirst stream on RUMBLE!!!!!
103K5 -
3:56:31
JakeParker
11 hours ago $14.38 earnedJakeParker is LIVE on Rumble
60.6K