Added list-local-ip.ps1

This commit is contained in:
Markus Fleschutz 2024-10-02 10:14:17 +02:00
parent 305077d5cd
commit ace08b19c6
7 changed files with 69 additions and 48 deletions

View File

@ -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,

1 DOMAIN DOMAIN,
2 a.root-servers.net abc.com
3 airbnb.com airbnb.com,
4 aka.ms aka.ms,
5 api.met.no api.met.no,
10 b.root-servers.net b.root-servers.net,
11 bing.com bing.com,
12 bitbucket.org bitbucket.org,
c.root-servers.net
13 client.dropbox.com client.dropbox.com,
14 cnn.com,
15 contacts.google.com contacts.google.com,
16 d.dropbox.com d.dropbox.com,
17 d.root-servers.net d.root-servers.net,

View File

@ -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 {

View File

@ -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)
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

View File

@ -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])"

View File

@ -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)

43
scripts/list-local-ip.ps1 Normal file
View File

@ -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
}

View File

@ -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"