PowerShell/docs/list-dns-servers.md

64 lines
2.0 KiB
Markdown
Raw Normal View History

2024-01-25 13:37:12 +01:00
Script: *list-dns-servers.ps1*
========================
2023-05-26 12:20:18 +02:00
list-dns-servers.ps1
2023-07-29 10:04:38 +02:00
Parameters
----------
2023-05-26 12:20:18 +02:00
```powershell
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
```
2023-07-29 10:04:38 +02:00
Script Content
--------------
2023-05-26 12:20:18 +02:00
```powershell
<#
.SYNOPSIS
Lists DNS servers
.DESCRIPTION
2024-03-27 17:36:59 +01:00
This PowerShell script list public and free DNS servers together with IPv4 addresses and measured latency.
2023-05-26 12:20:18 +02:00
.EXAMPLE
2023-08-06 21:36:33 +02:00
PS> ./list-dns-servers.ps1
2023-05-26 12:20:18 +02:00
2024-03-27 17:36:59 +01:00
DNS PROVIDER IPv4 ADDRESSES LATENCY
------------ ---- --------- -------
AdGuard DNS (Cyprus) 94.140.14.14 · 94.140.15.15 222 · 205 ms
2023-08-06 21:36:33 +02:00
...
2023-05-26 12:20:18 +02:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
2024-03-27 17:36:59 +01:00
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
2023-05-26 12:20:18 +02:00
2024-03-27 17:36:59 +01:00
$time=[system.diagnostics.stopwatch]::startNew();$null=(nslookup fleschutz.de $IPv4Sec 2>$null);[int]$lat2=$time.Elapsed.TotalMilliseconds
2023-05-26 12:20:18 +02:00
2024-03-27 17:36:59 +01:00
New-Object PSObject -Property @{ 'DNS PROVIDER'=$provider; 'IPv4 ADDRESSES'="$IPv4Pri · $IPv4Sec"; LATENCY="$lat1 · $lat2 ms" }
2023-05-26 12:20:18 +02:00
}
function List-DNS-Servers {
2024-03-27 17:36:59 +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) { MeasureDNSServer $row.PROVIDER $row.IPv4_PRI $row.IPv4_SEC }
2023-05-26 12:20:18 +02:00
}
try {
2024-03-27 17:36:59 +01:00
List-DNS-Servers | Format-Table -property @{e='DNS PROVIDER';width=50},@{e='IPv4 ADDRESSES';width=32},@{e='LATENCY';width=15}
2023-05-26 12:20:18 +02:00
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
```
2024-08-15 09:51:46 +02:00
*(generated by convert-ps2md.ps1 using the comment-based help of list-dns-servers.ps1 as of 08/15/2024 09:50:49)*