'Get DNS resolution time with BATCH (cmd)

I'm trying to obtain the resolution time of my DNS server, but I'm not sure that I'm doing it well.

First of all I tried to make a ping to my DNS server IP, and catch the time value, but i'm not sure that it's the correct value because I think that this value is the time to make a request and get a response to this IP.

Then I tried to make 2 diferent pings, one like this: "ping www.google.es" and the second one like: "ping googleIP" and compare the time but the time is exactly the same.

Finally I tried to search one command that gives me this information but I can't find it. I tried the nslookup but it isn'tthe answer that I need. Does there exist any command or any way to get this information?

Thank you. :)



Solution 1:[1]

Update: C.J. Jackson rightfully notes that when measuring DNS resolution times, you have to account for caching. I thought this would be a given when answering and focussed on the aspect of measuring command runtime. But sure, you'd need to do ipconfig /flushdns to clear the local DNS cache between runs, to really measure your DNS servers performance.


nslookup performs a name resolution against a DNS server - so this is the right command to use. But as you already noted, it does not display the time it takes for the name resolution. It's possible to do that with Windows' own powershell:

powershell "Measure-Command { nslookup www.google.es }"

Now, this outputs on my system...

Non-authoritative answer:


Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 0
Milliseconds      : 31
Ticks             : 317898
TotalDays         : 3,679375E-07
TotalHours        : 8,8305E-06
TotalMinutes      : 0,00052983
TotalSeconds      : 0,0317898
TotalMilliseconds : 31,7898

If you want to use this value programatically you'd filter with FINDSTR:

powershell "Measure-Command { nslookup www.google.es }" | FINDSTR "^Milliseconds"

Unfortunately, this still outputs Non-authoritative answer: which is printed by nslookup to STDERR. In contrast to batch, you can't redirect to NUL in powershell - instead you need to redirect to $null:

powershell "Measure-Command { nslookup www.google.es 2> $null }" | FINDSTR "^Milliseconds"

Output:

Milliseconds      : 31

Alternatively, as pointed out by Stephan, you could also move the redirection outside to the powershell invocation and thus out of the time measurement (which amounts to ~2ms difference on my end). This works since powershell outputs to STDOUT instead of STDERR:

powershell "Measure-Command { nslookup www.google.es }" 2>NUL | FINDSTR "^Milliseconds"

Solution 2:[2]

You have some free or OPEN tools to benchmark your DNS :

https://www.grc.com/dns/benchmark.htm

https://www.grc.com/dns/benchmark.htm

https://code.google.com/p/namebench/

or WEB based tools like :

http://network-speed.com/dnstime.php

http://www.dnsstuff.com/tools

Solution 3:[3]

apologies for bumping in and reviving an old thread.

zb226 set me in the right direction with Measure-Command. However, I've found that using native powershell cmdlets (I believe you need powershell 4.0) produces better and more accurate results (nslookup spawns a process, which can add time to the measurement), while also allowing more control over the query parameters. Also, seemingly the DNS cache doesn't have to be flushed, as passing the -DnsOnly argument forces it to send request to DNS serves, which implies it skips the cache, and can be can be combined with -NoHostsFile.

powershell command:

(Measure-Command {Resolve-DnsName -Name www.google.co.uk -Server 192.168.50.1 -DnsOnly -NoHostsFile -Type A_AAAA}).TotalMilliseconds

Output:

2.8373

For more info on Resolve-DnsName, type Get-Help Resolve-DnsName -Full in powershell.

Running the command once will show the performance for one query. DNS server performance needs to be monitored continously, as the response time varies due to different factors.

>> Clear-DnsClientCache
>> sleep 5
>> (Measure-Command {Resolve-DnsName -Name www.google.co.uk -Server 192.168.50.1 -DnsOnly -NoHostsFile -Type A_AAAA}).TotalMilliseconds
>> (Measure-Command {Resolve-DnsName -Name www.google.co.uk -Server 192.168.50.1 -DnsOnly -NoHostsFile -Type A_AAAA}).TotalMilliseconds
>> (Measure-Command {Resolve-DnsName -Name www.google.co.uk -Server 192.168.50.1 -DnsOnly -NoHostsFile -Type A_AAAA}).TotalMilliseconds
>> (Measure-Command {Resolve-DnsName -Name www.google.co.uk -Server 192.168.50.1 -DnsOnly -NoHostsFile -Type A_AAAA}).TotalMilliseconds
>> (Measure-Command {Resolve-DnsName -Name www.google.co.uk -Server 192.168.50.1 -DnsOnly -NoHostsFile -Type A_AAAA}).TotalMilliseconds
>> (Measure-Command {Resolve-DnsName -Name www.google.co.uk -Server 192.168.50.1 -DnsOnly -NoHostsFile -Type A_AAAA}).TotalMilliseconds
>> (Measure-Command {Resolve-DnsName -Name www.google.co.uk -Server 192.168.50.1 -DnsOnly -NoHostsFile -Type A_AAAA}).TotalMilliseconds
>> (Measure-Command {Resolve-DnsName -Name www.google.co.uk -Server 192.168.50.1 -DnsOnly -NoHostsFile -Type A_AAAA}).TotalMilliseconds
>> (Measure-Command {Resolve-DnsName -Name www.google.co.uk -Server 192.168.50.1 -DnsOnly -NoHostsFile -Type A_AAAA}).TotalMilliseconds
>> (Measure-Command {Resolve-DnsName -Name www.google.co.uk -Server 192.168.50.1 -DnsOnly -NoHostsFile -Type A_AAAA}).TotalMilliseconds
>> (Measure-Command {Resolve-DnsName -Name www.google.co.uk -Server 192.168.50.1 -DnsOnly -NoHostsFile -Type A_AAAA}).TotalMilliseconds
>> (Measure-Command {Resolve-DnsName -Name www.google.co.uk -Server 192.168.50.1 -DnsOnly -NoHostsFile -Type A_AAAA}).TotalMilliseconds
>> (Measure-Command {Resolve-DnsName -Name www.google.co.uk -Server 192.168.50.1 -DnsOnly -NoHostsFile -Type A_AAAA}).TotalMilliseconds
>> (Measure-Command {Resolve-DnsName -Name www.google.co.uk -Server 192.168.50.1 -DnsOnly -NoHostsFile -Type A_AAAA}).TotalMilliseconds
>> (Measure-Command {Resolve-DnsName -Name www.google.co.uk -Server 192.168.50.1 -DnsOnly -NoHostsFile -Type A_AAAA}).TotalMilliseconds
>> (Measure-Command {Resolve-DnsName -Name www.google.co.uk -Server 192.168.50.1 -DnsOnly -NoHostsFile -Type A_AAAA}).TotalMilliseconds
>> (Measure-Command {Resolve-DnsName -Name www.google.co.uk -Server 192.168.50.1 -DnsOnly -NoHostsFile -Type A_AAAA}).TotalMilliseconds
2.9599
3.1029
2.3041
2.2375
2.2498
2.2591
2.2046
2.2411
2.1638
2.191
2.1616
2.1721
2.2249
2.1563
2.3463
4.696
2.2989

The above command can easily be put in a function to query different servers with different parameters and utilised in a loop for continous measurement of DNS performance over time or used in the batch example by zb226.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 SachaDee
Solution 3