Noob, here. The “arp -a” command shows all the ip addresses and their associated MACs on the subnet, but I’d like to go a step further and see the hostname, too. It looks like I’m getting my array of IP addresses OK, but from there I can’t seem to get this command to work on the array:
That command will work just fine, but I’m unsure how to loop an array through it. Here’s what I’ve got, and it’s not working (I’ve pieced this together–it’s not all making sense to me):
$iparray = @() (arp -a) | Foreach{ $obj = New-Object PSObject -Property @{ IP = ($_ -split "s+")[1] } $iparray += $obj } foreach ($ip in $iparray) { [System.Net.Dns]::GetHostByAddress($ip).Hostname }
submitted by /u/motsanciens
[link] [comments]
The post Working with output from “arp -a” appeared first on How to Code .NET.