Skip to content

Instantly share code, notes, and snippets.

@mkbabb
Last active May 8, 2025 16:06
Show Gist options
  • Save mkbabb/66b1b61d985fc29ab587d30e3e6642bf to your computer and use it in GitHub Desktop.
Save mkbabb/66b1b61d985fc29ab587d30e3e6642bf to your computer and use it in GitHub Desktop.
DNS Resolution Test Script

I'll complete the text with the process management information:

This script performs DNS TXT record lookups once per minute for 24 hours straight. Each lookup uses a unique random name in the format 'delver-xxxxxxxx'.

Requirements

  • Python 3.x
  • Your computer must stay awake the entire time (disable sleep/hibernate)
  • Internet connection for the full 24 hours

Running

First, copy and paste the below Python code into a file called dns_lookup.py. Then, run it by:

on macOS/Linux:

python3 dns_lookup.py > output.log 2>&1 &

on Windows:

python dns_lookup.py > output.log 2>&1

Wherein dns_lookup.py is the path to your above created file, and output.log is the path to your desired output log file; the script will write all output thereto and run in the background.

Stopping the Test

If at any point you wish to stop the test you can do so by running the following:

on macOS/Linux:

ps aux | grep dns_lookup.py  # Find the process ID (PID)
kill <PID>                   # Stop the process

on Windows:

Get-Process -Name python | Where-Object { $_.CommandLine -like '*dns_lookup.py*' } | Select-Object Id  # Find PID
Stop-Process -Id <PID>  # Stop the process

Note: Your computer must not go to sleep during the test!

import subprocess
import time
import uuid
from datetime import datetime
def generate_name():
# Generate a UUID and take first 8 characters
random_id = str(uuid.uuid4())[:8]
return f"delver-{random_id}"
def perform_dns_lookup():
name = generate_name()
domain = f"{name}.dns.friday.institute"
nameserver = "ns-1.friday.institute"
print(f"Looking up domain: {domain}")
try:
result = subprocess.run(
['nslookup', '-type=TXT', domain, nameserver],
capture_output=True,
text=True,
)
print(result.stdout)
if result.stderr:
print("Errors:", result.stderr)
except Exception as e:
print(f"Error performing lookup: {e}")
def main():
iterations = 24 * 60 # 24 hours * 60 minutes
print(f"Starting DNS lookups at {datetime.now()}")
print(f"Will run for 24 hours ({iterations} iterations)")
for i in range(iterations):
print(f"\nIteration {i + 1} of {iterations} at {datetime.now()}")
perform_dns_lookup()
# Sleep for 60 seconds if not the last iteration
if i < iterations - 1:
time.sleep(60)
print(f"\nCompleted all lookups at {datetime.now()}")
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\nScript interrupted by user")
except Exception as e:
print(f"\nScript error: {e}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment