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)
-
1:04:47
The Bitcoin Family
23 hours agoBITCOIN SUNDAY LIVE AMA DIDI TAIHUTTU
16.5K3 -
7:10:05
Akademiks
9 hours agoDrake vs Kendrick Lamar. Who winning currently. Family Matters vs Not Like Us. Drake on Clock?
96.8K112 -
6:25:45
SNEAKO
8 hours agoTHERE'S A LOT TO DISCUSS...
92.5K44 -
59:42
The Late Kick with Josh Pate
14 hours agoLate Kick Live Ep 510: Bold Prediction Season | FSU vs Miami | G5 Perception vs Reality | A&M Future
33.3K5 -
2:02:18
vivafrei
19 hours agoEp. 209: Trump Trial; Ole Miss; Pennsylvania Farmers; Owen Shroyer; Whitmer & MORE!
149K228 -
1:27:31
RealitySurvival
9 hours agoPrepper SITREP: With Ethical Preparedness
58.3K9 -
3:40:49
XrayGirl
16 hours agoGTFO | Sunday Funday with Kara Lynne, QBG and HeelvsBabyface
57.2K7 -
2:16:20
George Galloway
2 days agoTHE FINAL COUNTDOWN - MOATS with George Galloway Ep 340
92.5K176 -
Major League Fishing
5 days agoBass Pro Tour LIVE - Stage Three - Day 4
88K7 -
29:33
Front & Center with Jacquie Jordan
2 days agoFront & Center w/ Jacquie Jordan - Unmasking the Masks
114K71