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)
-
7:35
Gun Owners Of America
15 hours agoTrump Promised To Sign This Bill
2.06K4 -
18:20
Bearing
20 hours agoSimp Gets BRUTALLY DESTROYED By His Crush 💔
3.99K22 -
4:11:09
Film Threat
1 day agoGOLDEN GLOBES WATCH PARTY 2025 | Film Threat Awards LIVE Coverage
59.3K4 -
3:40:42
MyronGainesX
12 hours agoFormer Fed Explains The Torso Killer
105K11 -
2:43:18
Nerdrotic
11 hours ago $17.13 earnedCybertruck Explosion Rabbit Hole | Forbidden Frontier #086
93.2K19 -
3:28:23
vivafrei
18 hours agoEop. 244: FBI Seeks HELP for Jan. 6? FBI Taints New Orleans Crime Scene? Amos Miller, Lawfare & MORE
229K299 -
2:27:48
Joker Effect
10 hours ago2025 already started up with a bang! Alex Jones, Bree, Elon Musk, Nick Fuentes, Fousey
53.6K15 -
LIVE
Vigilant News Network
16 hours agoEXPOSED: Secret Government Plot to Deploy Aerosolized ‘Vaccines’ Using Drones | Media Blackout
1,738 watching -
1:13:49
Josh Pate's College Football Show
13 hours ago $12.17 earnedSemifinal Predictions: OhioSt v Texas | Notre Dame v PennSt | Playoff Cinderella | Alabama’s Future
88.8K4 -
27:56
The Why Files
1 day agoThe Seventh Experiment: Lacerta Reveals the Truth of our Creation
141K80