Recently I started working on another side IoT Project. As part of that I needed to identify the Vendor / Manufacturer of networking equipment. As you are probably aware each network device has a unique MAC Address. A MAC Address looks like this 60:5b:b4:f9:63:05. The first 24 bits (6 hex characters) detail the vendor / manufacturer.
There are a number of online lookup tools to determine who the vendor is from the MAC address. And some like that one have an API to allow lookup too. If you are only looking up small volumes that is all good, but after that you get into subscription fee costs. I needed more than 1000 per day, but I also had a good idea of what the vendors were likely to be for a lot of my requests. So I rolled my own using an Azure Trigger Function.
Overview
The IEEE standards body maintains a list of the manufacturers assigned the 24 bit identifiers. A full list can be found here which is updated regularly. I downloaded this list and wrote a simple parser that created a PowerShell Object with the Hex, Base16 and Name of each Manufacturer.
I then extracted the manufacturers I expect to need to reference/lookup into a PSObject that is easily exportable and importable (export-clixml / import-clixml) and use that locally in my application. The full list to too large to keep locally so I exported the full list (again using export-clixml) and implemented a lookup as an Azure Function (that reads in the full list as a PSObject that takes ~1.7 seconds for 25,000+ records) which can then be queried with either Hex or Base16 as per the format in the IEEE list and the vendor name is returned.
Converting the IEEE List to a PowerShell Object
This little script will download the latest version of the OUI list and convert to a PowerShell Object. The resulting object looks like this:
vendor base16 hex ------ ------ --- Apple, Inc. F0766F 40-CB-C0 Apple, Inc. 40CBC0 40-98-AD Apple, Inc. 4098AD 6C-4D-73
Update:
- Line 4 for the local location to output the OUI List too
- Line 39 for the PSObject file to create
If you want to query the file locally using PowerShell you can like this:
$query="64-70-33" $result = $vendors | Select-Object | Where-Object {$_.hex -like $query} $result
vendor base16 hex ------ ------ --- Apple, Inc. 50A67F 64-70-33
If you want to extract all entries associated with a hardware vendor (e.g Apple) you can like this;
$apple = $vendors | Select-Object | Where-Object {$_.vendor -like "Apple*"}
and FYI, Apple have 671 registrations. Yes they make a LOT of equipment.
Azure Function
Here is the Azure Trigger PowerShell Function that takes a JSON object with a query containing the Base16 or Hex values for the 24bit Vendor Manufacturer and returns the Vendor / Manufacturer. e.g
{"query": "0A-00-27"}
Don’t forget to upload the Vendors.xml exported above to your Azure Function (you can drag and drop using Kudu) and update the path in Line 7.
An example PowerShell script to query would be similar to the following. Update $queryURI with the URI to your Azure Function.
$queryURI = "https://FUNCTIONAPP.azurewebsites.net/api/AZUREFUNCTION?code=12345678/uiEx6kse6NujQG0b4OIcjx6B2wHLhZepBD/8Jy6fFawg==" $query = "0A-00-27" $body = @{"query" = $query} | ConvertTo-Json $result=Invoke-RestMethod-Method Post -Uri $queryURI-Body $body $result
Microsoft Corporation
To lookup all MAC addresses from your local windows computer the following snippet will do that after updating $queryURI for you Azure Function.
# Query MAC Address $queryURI = "https://FUNCTIONAPP.azurewebsites.net/api/AZUREFUNCTION?code=12345678/uiEx6kse6NujQG0b4OIcjx6B2wHLhZepBD/8Jy6fFawg==" $netAdaptors = Get-NetAdapter foreach ($adaptor in $netAdaptors){ $mac=$adaptor.MacAddress $macV=$mac.Split("-") $macLookup="$($macV[0])$($macV[1])$($macV[2])" $body=@{"query"=$macLookup} |ConvertTo-Json $result=Invoke-RestMethod-Method Post -Uri $queryURI-Body $body-Headers @{"content-type"="application/text"} Write-Host-ForegroundColor Blue $result }
Summary
With the power of PowerShell it is quick to take a large amount of information and transform it into a usable collection that can then also be quickly exported and re-imported. It is also quickly searchable and thanks to Azure Functions supporting PowerShell it’s simple to stand-up the collection and query it as required programatically.