Updated list-ip-addresses.ps1

This commit is contained in:
Markus Fleschutz 2024-06-18 20:35:42 +02:00
parent b5ff7b0a6c
commit bbb0a590cf

View File

@ -13,20 +13,20 @@
#>
function WriteLocalInterface($interface) {
$IPv4 = ""
$IPv6 = ""
$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 "") {
Write-Host "✅ Local $interface IP address $IPv4, $IPv6"
Write-Host "✅ Local $interface IP address $IPv4/$prefixLen, $IPv6"
}
}