From ace08b19c64612a8f537ceaf9c25bfcd5a29990d Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Wed, 2 Oct 2024 10:14:17 +0200 Subject: [PATCH] Added list-local-ip.ps1 --- data/popular-domains.csv | 6 +-- scripts/check-dns.ps1 | 16 +++---- scripts/check-network.ps1 | 13 +++--- scripts/clear-dns-cache.ps1 | 8 ++-- ...-ip-addresses.ps1 => list-internet-ip.ps1} | 27 ++---------- scripts/list-local-ip.ps1 | 43 +++++++++++++++++++ scripts/ping-remote-hosts.ps1 | 4 +- 7 files changed, 69 insertions(+), 48 deletions(-) rename scripts/{list-ip-addresses.ps1 => list-internet-ip.ps1} (60%) create mode 100644 scripts/list-local-ip.ps1 diff --git a/data/popular-domains.csv b/data/popular-domains.csv index 50990c68..da571791 100644 --- a/data/popular-domains.csv +++ b/data/popular-domains.csv @@ -1,5 +1,5 @@ DOMAIN, -a.root-servers.net, +abc.com airbnb.com, aka.ms, api.met.no, @@ -10,8 +10,8 @@ amazon.com, b.root-servers.net, bing.com, bitbucket.org, -c.root-servers.net, client.dropbox.com, +cnn.com, contacts.google.com, d.dropbox.com, d.root-servers.net, @@ -98,4 +98,4 @@ www.whatsapp.com, www.whitehouse.gov, www.windy.com, www.wikipedia.org, -www.youtube.com, +www.youtube.com, \ No newline at end of file diff --git a/scripts/check-dns.ps1 b/scripts/check-dns.ps1 index 6740edc3..a0180a49 100755 --- a/scripts/check-dns.ps1 +++ b/scripts/check-dns.ps1 @@ -2,10 +2,10 @@ .SYNOPSIS Check the DNS resolution .DESCRIPTION - This PowerShell script measures the DNS resolution speed (using 100 popular domains) and prints it. + This PowerShell script measures the DNS resolution speed using 100 internet domains and prints it. .EXAMPLE PS> ./check-dns.ps1 - ✅ DNS resolves 56.5 domains per second + ✅ Internet DNS resolves 56.5 domains/sec .LINK https://github.com/fleschutz/PowerShell .NOTES @@ -13,24 +13,22 @@ #> try { - #Write-Progress "Measuring DNS resolution..." $table = Import-CSV "$PSScriptRoot/../data/popular-domains.csv" - $numRows = $table.Length $stopWatch = [system.diagnostics.stopwatch]::startNew() if ($IsLinux) { foreach($row in $table){$nop=dig $row.Domain +short} } else { + Clear-DnsClientCache foreach($row in $table){$nop=Resolve-DNSName $row.Domain} } [float]$elapsed = $stopWatch.Elapsed.TotalSeconds - #Write-Progress -completed "Measuring DNS resolution..." - $average = [math]::round($numRows / $elapsed, 1) - if ($average -lt 10.0) { - Write-Host "⚠️ DNS resolves $average domains per second only" + $speed = [math]::round($table.Length / $elapsed, 1) + if ($speed -lt 10.0) { + Write-Host "⚠️ Internet DNS resolves $speed domains/sec only" } else { - Write-Host "✅ DNS resolves $average domains per second" + Write-Host "✅ Internet DNS resolves $speed domains/sec" } exit 0 # success } catch { diff --git a/scripts/check-network.ps1 b/scripts/check-network.ps1 index f59db1da..0d96d076 100755 --- a/scripts/check-network.ps1 +++ b/scripts/check-network.ps1 @@ -1,13 +1,13 @@ <# .SYNOPSIS - Checks the network details + Checks the network .DESCRIPTION This PowerShell script queries the network details of the local computer and prints it. .EXAMPLE PS> ./check-network.ps1 - N E T W O R K - ✅ Online with 30ms latency (16ms..56ms, 0/10 loss) + N E T W O R K + ✅ Firewall enabled ... .LINK https://github.com/fleschutz/PowerShell @@ -17,10 +17,11 @@ Write-Host "`n N E T W O R K" -foregroundColor green & "$PSScriptRoot/check-firewall" -& "$PSScriptRoot/list-ip-addresses.ps1" +& "$PSScriptRoot/list-local-ip.ps1" & "$PSScriptRoot/ping-local-devices.ps1" -& "$PSScriptRoot/list-ssh-key.ps1" +& "$PSScriptRoot/check-vpn.ps1" +& "$PSScriptRoot/list-internet-ip.ps1" & "$PSScriptRoot/ping-remote-hosts.ps1" & "$PSScriptRoot/check-dns.ps1" -& "$PSScriptRoot/check-vpn.ps1" +& "$PSScriptRoot/list-ssh-key.ps1" exit 0 # success diff --git a/scripts/clear-dns-cache.ps1 b/scripts/clear-dns-cache.ps1 index 8d34790d..253281f7 100755 --- a/scripts/clear-dns-cache.ps1 +++ b/scripts/clear-dns-cache.ps1 @@ -5,7 +5,7 @@ This PowerShell script clears the DNS client cache of the local computer. .EXAMPLE PS> ./clear-dns-cache.ps1 - ✅ Cleared DNS cache in 1 sec + ✅ Cleared DNS cache in 1s. .LINK https://github.com/fleschutz/PowerShell .NOTES @@ -13,12 +13,12 @@ #> try { - $StopWatch = [system.diagnostics.stopwatch]::startNew() + $stopWatch = [system.diagnostics.stopwatch]::startNew() Clear-DnsClientCache - [int]$Elapsed = $StopWatch.Elapsed.TotalSeconds - "✅ Cleared DNS cache in $Elapsed sec" + [int]$elapsed = $stopWatch.Elapsed.TotalSeconds + "✅ Cleared DNS cache in $($elapsed)s." exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" diff --git a/scripts/list-ip-addresses.ps1 b/scripts/list-internet-ip.ps1 similarity index 60% rename from scripts/list-ip-addresses.ps1 rename to scripts/list-internet-ip.ps1 index 39415b6d..3b977e96 100755 --- a/scripts/list-ip-addresses.ps1 +++ b/scripts/list-internet-ip.ps1 @@ -1,10 +1,10 @@ <# .SYNOPSIS - Lists the IP addresses + Lists the Internet IP address .DESCRIPTION - This PowerShell script queries all IP address information and prints it. + This PowerShell script queries all public IP address information and prints it. .EXAMPLE - PS> ./list-ip-addresses.ps1 + PS> ./list-internet-ip.ps1 ✅ Internet IP 185.72.229.161, 2003:f2:6128:fd01:e543:601:30c2:a028 near Munich, Germany .LINK https://github.com/fleschutz/PowerShell @@ -12,24 +12,6 @@ Author: Markus Fleschutz | License: CC0 #> -function WriteLocalInterface($interface) { - $IPv4 = $IPv6 = $prefixLen = "" - $addresses = Get-NetIPAddress - foreach ($addr in $addresses) { - if ($addr.InterfaceAlias -like "$($interface)*") { - if ($addr.AddressFamily -eq "IPv4") { - $IPv4 = $addr.IPAddress - $prefixLen = $addr.PrefixLength - } else { - $IPv6 = $addr.IPAddress - } - } - } - if ($IPv4 -ne "" -or $IPv6 -ne "") { - "✅ Local $interface IP $IPv4/$prefixLen, $IPv6" - } -} - try { if ($IsLinux) { [string]$publicIPv4 = (curl -4 --silent ifconfig.co) @@ -37,9 +19,6 @@ try { [string]$city = (curl --silent ifconfig.co/city) [string]$country = (curl --silent ifconfig.co/country) } else { - WriteLocalInterface "Ethernet" - WriteLocalInterface "WLAN" - WriteLocalInterface "Bluetooth" [string]$publicIPv4 = (curl.exe -4 --silent ifconfig.co) [string]$publicIPv6 = (curl.exe -6 --silent ifconfig.co) [string]$city = (curl.exe --silent ifconfig.co/city) diff --git a/scripts/list-local-ip.ps1 b/scripts/list-local-ip.ps1 new file mode 100644 index 00000000..e253ad01 --- /dev/null +++ b/scripts/list-local-ip.ps1 @@ -0,0 +1,43 @@ +<# +.SYNOPSIS + List local IP addresses +.DESCRIPTION + This PowerShell script queries all local IP address information and prints it. +.EXAMPLE + PS> ./list-local-ip.ps1 + ✅ Local Ethernet IP 192.168.178.21/24, 2003:f2:670b:e700:31e5:de86:b7cd:4e45 +.LINK + https://github.com/fleschutz/PowerShell +.NOTES + Author: Markus Fleschutz | License: CC0 +#> + +function WriteLocalInterface($interface) { + $IPv4 = $IPv6 = $prefixLen = "" + $addresses = Get-NetIPAddress + foreach ($addr in $addresses) { + if ($addr.InterfaceAlias -like "$($interface)*") { + if ($addr.AddressFamily -eq "IPv4") { + $IPv4 = $addr.IPAddress + $prefixLen = $addr.PrefixLength + } else { + $IPv6 = $addr.IPAddress + } + } + } + if ($IPv4 -ne "" -or $IPv6 -ne "") { + "✅ Local $interface IP $IPv4/$prefixLen, $IPv6" + } +} + +try { + if ($IsLinux) { exit 0 } + + WriteLocalInterface "Ethernet" + WriteLocalInterface "WLAN" + WriteLocalInterface "Bluetooth" + exit 0 # success +} catch { + "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + exit 1 +} diff --git a/scripts/ping-remote-hosts.ps1 b/scripts/ping-remote-hosts.ps1 index 8dc5e9a7..c75964d8 100755 --- a/scripts/ping-remote-hosts.ps1 +++ b/scripts/ping-remote-hosts.ps1 @@ -7,7 +7,7 @@ Specifies the hosts to ping, seperated by commata (10 Internet servers by default) .EXAMPLE PS> ./ping-remote-hosts.ps1 - ✅ Online with 11...40ms latency - 18ms average + ✅ Internet latency 12ms (9...18ms range) .LINK https://github.com/fleschutz/PowerShell .NOTES @@ -36,7 +36,7 @@ try { Write-Host "⚠️ Internet offline (100% ping loss)" } elseif ($loss -eq 0) { $avg /= $success - Write-Host "✅ Internet latency $($min)...$($max)ms, average is $($avg)ms" + Write-Host "✅ Internet latency $($avg)ms ($($min)...$($max)ms range)" } else { $avg /= $success Write-Host "✅ Online with $loss/$total ping loss and $($min)...$($max)ms latency - $($avg)ms average"