2024-05-19 10:25:56 +02:00
|
|
|
Script: *list-network-neighbors.ps1*
|
|
|
|
========================
|
|
|
|
|
|
|
|
This PowerShell script lists all network neighbors of the local computer (using the ARP cache).
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
```powershell
|
|
|
|
PS> ./list-network-neighbors.ps1 [<CommonParameters>]
|
|
|
|
|
|
|
|
[<CommonParameters>]
|
|
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
|
|
```
|
|
|
|
|
|
|
|
Example
|
|
|
|
-------
|
|
|
|
```powershell
|
|
|
|
PS> ./list-network-neighbors.ps1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IPAddress InterfaceAlias LinkLayerAddress State
|
|
|
|
--------- -------------- ---------------- -----
|
|
|
|
192.168.178.43 Ethernet 2C-F0-5D-E7-8E-EE Reachable
|
|
|
|
...
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
Notes
|
|
|
|
-----
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
|
|
|
|
Related Links
|
|
|
|
-------------
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
|
|
|
Script Content
|
|
|
|
--------------
|
|
|
|
```powershell
|
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Lists the (cached) network neighbors
|
|
|
|
.DESCRIPTION
|
|
|
|
This PowerShell script lists all network neighbors of the local computer (using the ARP cache).
|
|
|
|
.EXAMPLE
|
|
|
|
PS> ./list-network-neighbors.ps1
|
|
|
|
|
|
|
|
IPAddress InterfaceAlias LinkLayerAddress State
|
|
|
|
--------- -------------- ---------------- -----
|
|
|
|
192.168.178.43 Ethernet 2C-F0-5D-E7-8E-EE Reachable
|
|
|
|
...
|
|
|
|
.LINK
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
.NOTES
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
#>
|
|
|
|
|
|
|
|
try {
|
|
|
|
if ($IsLinux) {
|
|
|
|
& ip neigh | grep REACHABLE
|
|
|
|
} elseif ($IsMacOS) {
|
|
|
|
& ip neigh | grep REACHABLE
|
|
|
|
} else {
|
|
|
|
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}
|
|
|
|
}
|
|
|
|
exit 0 # success
|
|
|
|
} catch {
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2024-08-15 09:51:46 +02:00
|
|
|
*(generated by convert-ps2md.ps1 using the comment-based help of list-network-neighbors.ps1 as of 08/15/2024 09:50:50)*
|