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)
-
2:50:47
TimcastIRL
3 hours agoFOOD STAMPS OVER, Ending Nov 1, Food RIOTS May Spark Trump INSURRECTION ACT | Timcast IRL
177K77 -
2:18:46
Tucker Carlson
3 hours agoTucker Carlson Interviews Nick Fuentes
39.6K230 -
LIVE
Drew Hernandez
13 hours agoCANDACE OWENS CALLS CHARLIE KIRK STAFF INTO QUESTION?
1,222 watching -
47:03
Barry Cunningham
5 hours agoPRESIDENT TRUMP MEETS WITH THE PRIME MINISTER OF JAPAN!! AND MORE NEWS!
22.4K20 -
DVR
Flyover Conservatives
22 hours agoThe Dollar Devaluation Playbook: Gold, Bitcoin… and the “Genius Act” - Andy Schectman | FOC Show
11.5K3 -
LIVE
SpartakusLIVE
5 hours agoWZ Tonight || Battlefield 6 BATTLE ROYALE Tomorrow!
234 watching -
LIVE
megimu32
3 hours agoON THE SUBJECT: Halloween Nostalgia! LET’S GET SPOOKY! 👻
61 watching -
1:24:56
Glenn Greenwald
5 hours agoThe Unhinged Reactions to Zohran's Rise; Dems Struggle to Find a Personality; DHS, on Laura Loomer's Orders, Arrests UK Journalist and Israel Critic | SYSTEM UPDATE #538
105K58 -
Spartan
4 hours agoBack from worlds. Need a short break from Halo, so single player games for now
13.9K -
LIVE
Eternal_Spartan
12 hours ago🟢 Eternal Spartan Plays FF7 Rebirth Episode 15 | USMC Veteran
57 watching