Created
August 28, 2017 14:47
-
-
Save chaorace/fcd35dde7f53a1f0b9eac098b31ea7ff to your computer and use it in GitHub Desktop.
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
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