Bulk MAC address lookup
I had a list of MAC addresses and was trying to identify them by finding out as much as I could about them. This was so I could document what devices I had found on which switchports in a datacenter.
After looking them up in a router ARP table and doing a reverse DNS lookup on them I figured I’d try finding out the manufacturer to help me fill in the blanks where there was no hostname. I currently have to use Windows at work and we have a an authenticated corporate proxy.
This little powershell script takes a CSV file with a column header “MACaddress” and does a lookup against the macvendors.com API. It uses your default proxy and your default proxy credentials.
$proxy = [System.Net.WebRequest]::GetSystemWebProxy().GetProxy("http://api.macvendors.com/") $file = import-csv "ss.csv" foreach ($line in $file) { $mac = "" $uri = "" $manufacturer="" $mac = $line.MACaddress $uri = "http://api.macvendors.com/"+$mac $manufacturer = Invoke-RestMethod -uri $uri -proxy $proxy -ProxyUseDefaultCredentials $output = $mac+","+$manufacturer echo $output }
If you want to do the reverse DNS lookups that I did after you’ve extracted the IP from the ARP table then just use this little function in a script.
Function Get-DnsEntry($iphost) { If($ipHost -match "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$") { [System.Net.Dns]::GetHostEntry($iphost).HostName } ElseIf( $ipHost -match "^.*\.\.*") { [System.Net.Dns]::GetHostEntry($iphost).AddressList[0].IPAddressToString } ELSE { Throw "Specify either an IP V4 address or a hostname" } } #end Get-DnsEntry