Created
January 11, 2016 02:18
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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