Skip to content

Instantly share code, notes, and snippets.

@aplocher
Created January 11, 2016 02:18
Show Gist options
  • Save aplocher/e23262fa0f07b1e63200 to your computer and use it in GitHub Desktop.
Save aplocher/e23262fa0f07b1e63200 to your computer and use it in GitHub Desktop.
Output based on (and similar to) arp -a, but includes hostnames. Will take a few seconds longer to run since it must reverse resolve each IP.
$hostColWidth = 40
arp -a | % {
$line=$_.ToString().Trim()
try {
if ($line -like "Interface:*" -or $line -eq "") {
$line
} elseif ($line -like "Internet Address*") {
" " + "HostName".PadRight($hostColWidth, ' ') + $line
} else {
$res=[System.Net.Dns]::gethostentry($line.ToString().Trim().Split(" ")[0])
if ($res) {
" "+ $res.HostName.PadRight($hostColWidth, ' ') + $line
} else {
" " + "(NO HOST)".PadRight($hostColWidth, ' ') +$line
}
}
} catch [exception] {
" " + "(NO HOST)".PadRight($hostColWidth, ' ') + $line
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment