-
-
Notifications
You must be signed in to change notification settings - Fork 424
/
list-dns-servers.ps1
executable file
·41 lines (34 loc) · 1.5 KB
/
list-dns-servers.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<#
.SYNOPSIS
Lists DNS servers
.DESCRIPTION
This PowerShell script list public and free DNS servers together with IPv4 addresses and measured latency.
.EXAMPLE
PS> ./list-dns-servers.ps1
DNS PROVIDER IPv4 ADDRESSES LATENCY
------------ ---- --------- -------
AdGuard DNS (Cyprus) 94.140.14.14 · 94.140.15.15 222 · 205 ms
...
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
function MeasureDNSServer([string]$provider, [string]$IPv4Pri, [string]$IPv4Sec) {
$time=[system.diagnostics.stopwatch]::startNew();$null=(nslookup fleschutz.de $IPv4Pri 2>$null);[int]$lat1=$time.Elapsed.TotalMilliseconds
$time=[system.diagnostics.stopwatch]::startNew();$null=(nslookup fleschutz.de $IPv4Sec 2>$null);[int]$lat2=$time.Elapsed.TotalMilliseconds
New-Object PSObject -Property @{ 'DNS PROVIDER'=$provider; 'IPv4 ADDRESSES'="$IPv4Pri · $IPv4Sec"; LATENCY="$lat1 · $lat2 ms" }
}
function List-DNS-Servers {
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) { MeasureDNSServer $row.PROVIDER $row.IPv4_PRI $row.IPv4_SEC }
}
try {
List-DNS-Servers | Format-Table -property @{e='DNS PROVIDER';width=50},@{e='IPv4 ADDRESSES';width=32},@{e='LATENCY';width=15}
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}