Skip to content

Instantly share code, notes, and snippets.

@chaorace
Created August 28, 2017 14:47
Show Gist options
  • Save chaorace/fcd35dde7f53a1f0b9eac098b31ea7ff to your computer and use it in GitHub Desktop.
Save chaorace/fcd35dde7f53a1f0b9eac098b31ea7ff to your computer and use it in GitHub Desktop.
Param([switch]$l)
$raw = arp -a | Select-String 'dynamic'
[regex]$rgx = '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'
[regex]$arprgx = '\w{2}-\w{2}-\w{2}-\w{2}-\w{2}-\w{2}'
$ips = $rgx.Matches($raw) | %{$_.Value}
$hosts = $ips | % {
try{
[System.Net.Dns]::GetHostByAddress($_)
}catch{if($l){''}}
} | Select -Property HostName,AddressList
if($l){
$arps = $arprgx.Matches($raw).Value
$makes = $arps | % {
try{
Invoke-RestMethod -uri "http://api.macvendors.com/$_"
}catch{''}
}
For ($i=0; $i -lt $hosts.Length; $i++){
$hosts.Get($i) | Add-Member -NotePropertyName 'Vendor' -NotePropertyValue $makes.Get($i)
}
$hosts = $hosts | ?{$_.HostName -ne $null} | Sort -Property Vendor
}else{
$hosts = $hosts | Sort -Property HostName
}
$hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment