2024-11-08 12:38:20 +01:00
|
|
|
The *list-network-neighbors.ps1* Script
|
|
|
|
===========================
|
2024-05-19 10:25:56 +02:00
|
|
|
|
|
|
|
This PowerShell script lists all network neighbors of the local computer (using the ARP cache).
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
```powershell
|
2024-11-08 12:35:11 +01:00
|
|
|
/home/markus/Repos/PowerShell/scripts/list-network-neighbors.ps1 [<CommonParameters>]
|
2024-05-19 10:25:56 +02:00
|
|
|
|
|
|
|
[<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-11-20 11:52:20 +01:00
|
|
|
*(generated by convert-ps2md.ps1 as of 11/20/2024 11:51:56)*
|