Skip to content

Commit ace08b1

Browse files
committed
Added list-local-ip.ps1
1 parent 305077d commit ace08b1

7 files changed

+69
-48
lines changed

data/popular-domains.csv

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
DOMAIN,
2-
a.root-servers.net,
2+
abc.com
33
airbnb.com,
44
aka.ms,
55
api.met.no,
@@ -10,8 +10,8 @@ amazon.com,
1010
b.root-servers.net,
1111
bing.com,
1212
bitbucket.org,
13-
c.root-servers.net,
1413
client.dropbox.com,
14+
cnn.com,
1515
contacts.google.com,
1616
d.dropbox.com,
1717
d.root-servers.net,
@@ -98,4 +98,4 @@ www.whatsapp.com,
9898
www.whitehouse.gov,
9999
www.windy.com,
100100
www.wikipedia.org,
101-
www.youtube.com,
101+
www.youtube.com,

scripts/check-dns.ps1

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,33 @@
22
.SYNOPSIS
33
Check the DNS resolution
44
.DESCRIPTION
5-
This PowerShell script measures the DNS resolution speed (using 100 popular domains) and prints it.
5+
This PowerShell script measures the DNS resolution speed using 100 internet domains and prints it.
66
.EXAMPLE
77
PS> ./check-dns.ps1
8-
✅ DNS resolves 56.5 domains per second
8+
Internet DNS resolves 56.5 domains/sec
99
.LINK
1010
https://github.com/fleschutz/PowerShell
1111
.NOTES
1212
Author: Markus Fleschutz | License: CC0
1313
#>
1414

1515
try {
16-
#Write-Progress "Measuring DNS resolution..."
1716
$table = Import-CSV "$PSScriptRoot/../data/popular-domains.csv"
18-
$numRows = $table.Length
1917

2018
$stopWatch = [system.diagnostics.stopwatch]::startNew()
2119
if ($IsLinux) {
2220
foreach($row in $table){$nop=dig $row.Domain +short}
2321
} else {
22+
Clear-DnsClientCache
2423
foreach($row in $table){$nop=Resolve-DNSName $row.Domain}
2524
}
2625
[float]$elapsed = $stopWatch.Elapsed.TotalSeconds
2726

28-
#Write-Progress -completed "Measuring DNS resolution..."
29-
$average = [math]::round($numRows / $elapsed, 1)
30-
if ($average -lt 10.0) {
31-
Write-Host "⚠️ DNS resolves $average domains per second only"
27+
$speed = [math]::round($table.Length / $elapsed, 1)
28+
if ($speed -lt 10.0) {
29+
Write-Host "⚠️ Internet DNS resolves $speed domains/sec only"
3230
} else {
33-
Write-Host "✅ DNS resolves $average domains per second"
31+
Write-Host "Internet DNS resolves $speed domains/sec"
3432
}
3533
exit 0 # success
3634
} catch {

scripts/check-network.ps1

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<#
22
.SYNOPSIS
3-
Checks the network details
3+
Checks the network
44
.DESCRIPTION
55
This PowerShell script queries the network details of the local computer and prints it.
66
.EXAMPLE
77
PS> ./check-network.ps1
88
9-
N E T W O R K
10-
Online with 30ms latency (16ms..56ms, 0/10 loss)
9+
N E T W O R K
10+
Firewall enabled
1111
...
1212
.LINK
1313
https://github.com/fleschutz/PowerShell
@@ -17,10 +17,11 @@
1717

1818
Write-Host "`n N E T W O R K" -foregroundColor green
1919
& "$PSScriptRoot/check-firewall"
20-
& "$PSScriptRoot/list-ip-addresses.ps1"
20+
& "$PSScriptRoot/list-local-ip.ps1"
2121
& "$PSScriptRoot/ping-local-devices.ps1"
22-
& "$PSScriptRoot/list-ssh-key.ps1"
22+
& "$PSScriptRoot/check-vpn.ps1"
23+
& "$PSScriptRoot/list-internet-ip.ps1"
2324
& "$PSScriptRoot/ping-remote-hosts.ps1"
2425
& "$PSScriptRoot/check-dns.ps1"
25-
& "$PSScriptRoot/check-vpn.ps1"
26+
& "$PSScriptRoot/list-ssh-key.ps1"
2627
exit 0 # success

scripts/clear-dns-cache.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
This PowerShell script clears the DNS client cache of the local computer.
66
.EXAMPLE
77
PS> ./clear-dns-cache.ps1
8-
✅ Cleared DNS cache in 1 sec
8+
✅ Cleared DNS cache in 1s.
99
.LINK
1010
https://github.com/fleschutz/PowerShell
1111
.NOTES
1212
Author: Markus Fleschutz | License: CC0
1313
#>
1414

1515
try {
16-
$StopWatch = [system.diagnostics.stopwatch]::startNew()
16+
$stopWatch = [system.diagnostics.stopwatch]::startNew()
1717

1818
Clear-DnsClientCache
1919

20-
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
21-
"✅ Cleared DNS cache in $Elapsed sec"
20+
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
21+
"✅ Cleared DNS cache in $($elapsed)s."
2222
exit 0 # success
2323
} catch {
2424
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

scripts/list-ip-addresses.ps1 renamed to scripts/list-internet-ip.ps1

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,24 @@
11
<#
22
.SYNOPSIS
3-
Lists the IP addresses
3+
Lists the Internet IP address
44
.DESCRIPTION
5-
This PowerShell script queries all IP address information and prints it.
5+
This PowerShell script queries all public IP address information and prints it.
66
.EXAMPLE
7-
PS> ./list-ip-addresses.ps1
7+
PS> ./list-internet-ip.ps1
88
✅ Internet IP 185.72.229.161, 2003:f2:6128:fd01:e543:601:30c2:a028 near Munich, Germany
99
.LINK
1010
https://github.com/fleschutz/PowerShell
1111
.NOTES
1212
Author: Markus Fleschutz | License: CC0
1313
#>
1414

15-
function WriteLocalInterface($interface) {
16-
$IPv4 = $IPv6 = $prefixLen = ""
17-
$addresses = Get-NetIPAddress
18-
foreach ($addr in $addresses) {
19-
if ($addr.InterfaceAlias -like "$($interface)*") {
20-
if ($addr.AddressFamily -eq "IPv4") {
21-
$IPv4 = $addr.IPAddress
22-
$prefixLen = $addr.PrefixLength
23-
} else {
24-
$IPv6 = $addr.IPAddress
25-
}
26-
}
27-
}
28-
if ($IPv4 -ne "" -or $IPv6 -ne "") {
29-
"✅ Local $interface IP $IPv4/$prefixLen, $IPv6"
30-
}
31-
}
32-
3315
try {
3416
if ($IsLinux) {
3517
[string]$publicIPv4 = (curl -4 --silent ifconfig.co)
3618
[string]$publicIPv6 = (curl -6 --silent ifconfig.co)
3719
[string]$city = (curl --silent ifconfig.co/city)
3820
[string]$country = (curl --silent ifconfig.co/country)
3921
} else {
40-
WriteLocalInterface "Ethernet"
41-
WriteLocalInterface "WLAN"
42-
WriteLocalInterface "Bluetooth"
4322
[string]$publicIPv4 = (curl.exe -4 --silent ifconfig.co)
4423
[string]$publicIPv6 = (curl.exe -6 --silent ifconfig.co)
4524
[string]$city = (curl.exe --silent ifconfig.co/city)

scripts/list-local-ip.ps1

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<#
2+
.SYNOPSIS
3+
List local IP addresses
4+
.DESCRIPTION
5+
This PowerShell script queries all local IP address information and prints it.
6+
.EXAMPLE
7+
PS> ./list-local-ip.ps1
8+
✅ Local Ethernet IP 192.168.178.21/24, 2003:f2:670b:e700:31e5:de86:b7cd:4e45
9+
.LINK
10+
https://github.com/fleschutz/PowerShell
11+
.NOTES
12+
Author: Markus Fleschutz | License: CC0
13+
#>
14+
15+
function WriteLocalInterface($interface) {
16+
$IPv4 = $IPv6 = $prefixLen = ""
17+
$addresses = Get-NetIPAddress
18+
foreach ($addr in $addresses) {
19+
if ($addr.InterfaceAlias -like "$($interface)*") {
20+
if ($addr.AddressFamily -eq "IPv4") {
21+
$IPv4 = $addr.IPAddress
22+
$prefixLen = $addr.PrefixLength
23+
} else {
24+
$IPv6 = $addr.IPAddress
25+
}
26+
}
27+
}
28+
if ($IPv4 -ne "" -or $IPv6 -ne "") {
29+
"✅ Local $interface IP $IPv4/$prefixLen, $IPv6"
30+
}
31+
}
32+
33+
try {
34+
if ($IsLinux) { exit 0 }
35+
36+
WriteLocalInterface "Ethernet"
37+
WriteLocalInterface "WLAN"
38+
WriteLocalInterface "Bluetooth"
39+
exit 0 # success
40+
} catch {
41+
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
42+
exit 1
43+
}

scripts/ping-remote-hosts.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Specifies the hosts to ping, seperated by commata (10 Internet servers by default)
88
.EXAMPLE
99
PS> ./ping-remote-hosts.ps1
10-
Online with 11...40ms latency - 18ms average
10+
Internet latency 12ms (9...18ms range)
1111
.LINK
1212
https://github.com/fleschutz/PowerShell
1313
.NOTES
@@ -36,7 +36,7 @@ try {
3636
Write-Host "⚠️ Internet offline (100% ping loss)"
3737
} elseif ($loss -eq 0) {
3838
$avg /= $success
39-
Write-Host "✅ Internet latency $($min)...$($max)ms, average is $($avg)ms"
39+
Write-Host "✅ Internet latency $($avg)ms ($($min)...$($max)ms range)"
4040
} else {
4141
$avg /= $success
4242
Write-Host "✅ Online with $loss/$total ping loss and $($min)...$($max)ms latency - $($avg)ms average"

0 commit comments

Comments
 (0)