2023-10-31 12:33:36 +01:00
|
|
|
|
<#
|
2023-02-19 10:04:45 +01:00
|
|
|
|
.SYNOPSIS
|
|
|
|
|
Lists DNS servers
|
|
|
|
|
.DESCRIPTION
|
|
|
|
|
This PowerShell script measures the latency of public and free DNS servers and lists it.
|
|
|
|
|
.EXAMPLE
|
2023-08-06 21:35:36 +02:00
|
|
|
|
PS> ./list-dns-servers.ps1
|
2023-02-19 10:04:45 +01:00
|
|
|
|
|
2023-08-06 21:35:36 +02:00
|
|
|
|
Provider IPv4 Latency
|
|
|
|
|
-------- ---- -------
|
|
|
|
|
AdGuard DNS (Cyprus) 94.140.14.14 / 94.140.15.15 222 / 205 ms
|
|
|
|
|
...
|
2023-02-19 10:04:45 +01:00
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
.NOTES
|
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
function CheckDNSServer { param($Provider, $IPv4Pri, $IPv4Sec)
|
2023-04-07 14:00:34 +02:00
|
|
|
|
$SW=[system.diagnostics.stopwatch]::startNew();$null=(nslookup fleschutz.de $IPv4Pri 2>$null);[int]$Lat1=$SW.Elapsed.TotalMilliseconds
|
2023-02-19 10:04:45 +01:00
|
|
|
|
|
2023-04-07 14:00:34 +02:00
|
|
|
|
$SW=[system.diagnostics.stopwatch]::startNew();$null=(nslookup fleschutz.de $IPv4Sec 2>$null);[int]$Lat2=$SW.Elapsed.TotalMilliseconds
|
2023-02-19 10:04:45 +01:00
|
|
|
|
|
2023-04-07 14:00:34 +02:00
|
|
|
|
New-Object PSObject -Property @{ Provider=$Provider; IPv4="$IPv4Pri / $IPv4Sec"; Latency="$Lat1 / $Lat2 ms" }
|
2023-02-19 10:04:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function List-DNS-Servers {
|
2024-03-24 12:23:40 +01:00
|
|
|
|
Write-Progress "Loading data/public-dns-servers.csv..."
|
|
|
|
|
$table = Import-CSV "$PSScriptRoot/../data/public-dns-servers.csv"
|
|
|
|
|
Write-Progress -completed "Done."
|
|
|
|
|
foreach($row in $table) { CheckDNSServer $row.PROVIDER $row.IPv4_PRI $row.IPv4_SEC }
|
|
|
|
|
|
2023-02-19 10:04:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
List-DNS-Servers | Format-Table -property @{e='Provider';width=50},@{e='IPv4';width=32},@{e='Latency';width=15}
|
|
|
|
|
exit 0 # success
|
|
|
|
|
} catch {
|
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
|
exit 1
|
2023-08-06 21:35:36 +02:00
|
|
|
|
}
|