DNS
1 TopicDNS lookup performance
Hello all I've got this to do what I want but thought I'd run it past people who know more than me in the hope someone would be kind enough to advise on the following. The intention is to run this every few minutes using task scheduler, I'll push to one or more machines with an RMM. Questions. Is this an efficient an accurate way to do this? Are there any improvements anyone wants to suggest for the code Am I re-inventing a wheel that I can get somewhere for free or low cost? I'm waiting for the new version of GRC's DNS testing tool so this is a stopgap unless it works well enough. TIA # Define an array to store the DNS Servers to be queried with thier FQDN and IP address $dnsServers = @() # Add 5 hosts with their FQDN and IP addresses $dnsServers += [PSCustomObject]@{ FQDN = "OurDNS1"; IPAddress = "14.15.16.17" } $dnsServers += [PSCustomObject]@{ FQDN = "OurDNS2"; IPAddress = "11.12.13.14" } $dnsServers += [PSCustomObject]@{ FQDN = "Cloudflare"; IPAddress = "1.1.1.1" } $dnsServers += [PSCustomObject]@{ FQDN = "Quad9"; IPAddress = "9.9.9.9" } $dnsServers += [PSCustomObject]@{ FQDN = "Google"; IPAddress = "8.8.8.4" } # Define an array to store target FQDNs $targetFqdns = @( "bbc.co.uk", "www.porsche.com", "www.amazon.co.uk" ) # Get the current date in yyyy-MM-dd format $currentDate = Get-Date -Format "yyyy-MM-dd" # Define the path to the CSV file with the current date in the filename $filePath = "$PSScriptRoot\DNSResults_$currentDate.csv" # Initialize the CSV file with headers if it doesn't exist if (-not (Test-Path $filePath)) { "Timestamp,Milliseconds,TargetURL,DNSServerIP,DNSServer" | Out-File -FilePath $filePath } # Loop through each target host and then each DNS server foreach ($targetFqdn in $targetFqdns) { foreach ($dnsServer in $dnsServers) { # Measure the time taken to run the command $measure = Measure-Command -Expression { nslookup $targetFqdn $dnsServer > $null 2>&1 } # Get the current date and time in ISO 8601 format $timestamp = Get-Date -Format "yyyy-MM-ddTHH:mm:ss" # Get the total milliseconds and round up to a whole number $milliseconds = [math]::Ceiling($measure.TotalMilliseconds) # Append the timestamp, milliseconds, domain, server, and name to the CSV file $result = "$timestamp,$milliseconds,$targetFqdn," $dnsServerUSed = "$($dnsServer.IPAddress),$($dnsServer.FQDN)" $output = $result + $dnsServerUsed $output | Out-File -FilePath $filePath -Append } }77Views0likes2Comments