From 4de7ec9831bc18352c31e67f27d8a31e46414a66 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Sun, 24 Mar 2024 18:13:45 +0100 Subject: [PATCH] Update list-dns-servers.ps1 --- scripts/list-dns-servers.ps1 | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/list-dns-servers.ps1 b/scripts/list-dns-servers.ps1 index 0f780989..07170f62 100755 --- a/scripts/list-dns-servers.ps1 +++ b/scripts/list-dns-servers.ps1 @@ -2,13 +2,13 @@ .SYNOPSIS Lists DNS servers .DESCRIPTION - This PowerShell script measures the latency of public and free DNS servers and lists it. + This PowerShell script list public and free DNS servers together with IPv4 addresses and measured latency. .EXAMPLE PS> ./list-dns-servers.ps1 - Provider IPv4 Latency - -------- ---- ------- - AdGuard DNS (Cyprus) 94.140.14.14 / 94.140.15.15 222 / 205 ms + 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 @@ -16,24 +16,24 @@ Author: Markus Fleschutz | License: CC0 #> -function CheckDNSServer { param($Provider, $IPv4Pri, $IPv4Sec) - $SW=[system.diagnostics.stopwatch]::startNew();$null=(nslookup fleschutz.de $IPv4Pri 2>$null);[int]$Lat1=$SW.Elapsed.TotalMilliseconds +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 - $SW=[system.diagnostics.stopwatch]::startNew();$null=(nslookup fleschutz.de $IPv4Sec 2>$null);[int]$Lat2=$SW.Elapsed.TotalMilliseconds + $time=[system.diagnostics.stopwatch]::startNew();$null=(nslookup fleschutz.de $IPv4Sec 2>$null);[int]$lat2=$time.Elapsed.TotalMilliseconds - New-Object PSObject -Property @{ Provider=$Provider; IPv4="$IPv4Pri / $IPv4Sec"; Latency="$Lat1 / $Lat2 ms" } + 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) { CheckDNSServer $row.PROVIDER $row.IPv4_PRI $row.IPv4_SEC } + foreach($row in $table) { MeasureDNSServer $row.PROVIDER $row.IPv4_PRI $row.IPv4_SEC } } try { - List-DNS-Servers | Format-Table -property @{e='Provider';width=50},@{e='IPv4';width=32},@{e='Latency';width=15} + 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])"