2024-05-08 13:32:42 +02:00
|
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
2024-05-09 11:29:07 +02:00
|
|
|
|
Lists the (cached) network neighbors
|
2024-05-08 13:32:42 +02:00
|
|
|
|
.DESCRIPTION
|
2024-05-09 11:57:45 +02:00
|
|
|
|
This PowerShell script lists all network neighbors of the local computer (using the ARP cache).
|
2024-05-08 13:32:42 +02:00
|
|
|
|
.EXAMPLE
|
|
|
|
|
PS> ./list-network-neighbors.ps1
|
|
|
|
|
|
2024-05-09 11:57:45 +02:00
|
|
|
|
IPAddress InterfaceAlias LinkLayerAddress State
|
|
|
|
|
--------- -------------- ---------------- -----
|
|
|
|
|
192.168.178.43 Ethernet 2C-F0-5D-E7-8E-EE Reachable
|
2024-05-08 13:32:42 +02:00
|
|
|
|
...
|
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
.NOTES
|
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
try {
|
2024-05-09 11:29:07 +02:00
|
|
|
|
if ($IsLinux) {
|
2024-05-09 11:57:45 +02:00
|
|
|
|
& ip neigh | grep REACHABLE
|
2024-05-09 11:29:07 +02:00
|
|
|
|
} elseif ($IsMacOS) {
|
2024-05-09 11:57:45 +02:00
|
|
|
|
& ip neigh | grep REACHABLE
|
2024-05-09 11:29:07 +02:00
|
|
|
|
} else {
|
2024-05-09 11:57:45 +02:00
|
|
|
|
Get-NetNeighbor -includeAllCompartments -state Permanent,Reachable | Format-Table -property @{e='IPAddress';width=38},@{e='InterfaceAlias';width=14},@{e='LinkLayerAddress';width=19},@{e='State';width=12}
|
2024-05-09 11:29:07 +02:00
|
|
|
|
}
|
2024-05-08 13:32:42 +02:00
|
|
|
|
exit 0 # success
|
|
|
|
|
} catch {
|
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
|
exit 1
|
|
|
|
|
}
|