Skip to content

Latest commit

 

History

History
76 lines (65 loc) · 1.91 KB

File metadata and controls

76 lines (65 loc) · 1.91 KB

The 'check-dns.ps1' Script

This PowerShell script measures the DNS lookup speed using 100 internet domains and prints it.

Parameters

PS> ./check-dns.ps1 [<CommonParameters>]

[<CommonParameters>]
    This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, 
    WarningVariable, OutBuffer, PipelineVariable, and OutVariable.

Example

PS> ./check-dns.ps1
✅ Internet DNS lookup at 33.6ms on average (excellent)

Notes

Author: Markus Fleschutz | License: CC0

Related Links

https://github.com/fleschutz/PowerShell

Script Content

<#
.SYNOPSIS
	Checks the DNS speed 
.DESCRIPTION
	This PowerShell script measures the DNS lookup speed using 100 internet domains and prints it.
.EXAMPLE
	PS> ./check-dns.ps1
	✅ Internet DNS lookup at 33.6ms on average (excellent)
.LINK
	https://github.com/fleschutz/PowerShell
.NOTES
	Author: Markus Fleschutz | License: CC0
#>
 
try {
	$table = Import-CSV "$PSScriptRoot/data/popular-domains.csv"

	if ($IsLinux) {
		$stopWatch = [system.diagnostics.stopwatch]::startNew()
		foreach($row in $table){$nop=dig $row.Domain +short}
	} else {
		Clear-DnsClientCache
		$stopWatch = [system.diagnostics.stopwatch]::startNew()
		foreach($row in $table){$nop=Resolve-DNSName $row.Domain}
	}
	[float]$elapsed = $stopWatch.Elapsed.TotalSeconds * 1000.0
	$speed = [math]::round($elapsed / $table.Length, 1)
	if ($speed -lt 50.0) {
		"✅ Internet DNS lookup at $($speed)ms on average (excellent)"
	} elseif ($speed -lt 100.0) {
		"✅ Internet DNS lookup at $($speed)ms on average (good)"
	} else {  
		"⚠️ Internet DNS lookup at $($speed)ms on average (slow)"
	}
	exit 0 # success
} catch {
	"⚠️ ERROR: $($Error[0]) (at line $($_.InvocationInfo.ScriptLineNumber))"
	exit 1
}

(page generated by convert-ps2md.ps1 as of 04/19/2026 17:56:56)