How to resolve the algorithm MAC vendor lookup step by step in the APL programming language
How to resolve the algorithm MAC vendor lookup step by step in the APL programming language
Table of Contents
Problem Statement
Every connected device around the world comes with a unique Media Access Control address, or a MAC address. A common task a network administrator may come across is being able to identify a network device's manufacturer when given only a MAC address.
Interface with one (or numerous) APIs that exist on the internet and retrieve the device manufacturer based on a supplied MAC address. A MAC address that does not return a valid result should return the String "N/A". An error related to the network connectivity or the API should return a null result. Many implementations on this page use http://api.macvendors.com/ which, as of 19th September 2021, is throttling requests. After only 2 calls, the following response is returned for all subsequent requests. If you are planning to use the same provider or going to run the examples on this page, consider building in a delay between two calls. {"errors":{"detail":"Too Many Requests","message":"Please slow down your requests or upgrade your plan at https://macvendors.com"}}
Let's start with the solution:
Step by Step solution about How to resolve the algorithm MAC vendor lookup step by step in the APL programming language
Source code in the apl programming language
⍝load the library module
]load HttpCommand
⍝ define a direct function (dfn) to look up a single MAC address
vendorLookup1 ← { (HttpCommand.Get 'http://api.macvendors.com/',⍕⍵).Data }
⍝ define a traditional function to look up all the MAC addresses in a list with
⍝ a delay between calls
⍝ The header says that the function is named vendorLookup, it takes a single
⍝ parameter which we call macList, and the value of the local variable
⍝ vendors will become the function's return value
∇ vendors ← vendorLookup macList
⍝ look up the first vendor and put it into an array in our return var
vendors ← ⊆vendorLookup1 1↑macList
⍝ Loop over the rest of the array
:For burger :In 1↓macList
⎕DL 2 ⍝ wait 2 seconds
vendors ⍪← ⊆vendorLookup1 burger ⍝ then look up the next vendor and append
:EndFor
∇
⍝ demo data
macList ← '88:53:2E:67:07:BE' 'D4:F4:6F:C9:EF:8D' 'FC:FB:FB:01:FA:21'
macList ⍪← '4c:72:b9:56:fe:bc' '00-14-22-01-23-45'
⍝ look up the vendors (takes a while with the 2-second delay between lookups)
vendorList ← vendorLookup macList
⍝ the result is an array (a 1-row by N-column matrix). to print out one vendor
⍝ per line, we reshape it to be N rows by 1 column instead.
{(1⌷⍴⍵) 1 ⍴ ⍵} vendorList
You may also check:How to resolve the algorithm Binary strings step by step in the Groovy programming language
You may also check:How to resolve the algorithm Loops/Nested step by step in the Scilab programming language
You may also check:How to resolve the algorithm Long multiplication step by step in the Julia programming language
You may also check:How to resolve the algorithm Compiler/virtual machine interpreter step by step in the Forth programming language
You may also check:How to resolve the algorithm Walk a directory/Recursively step by step in the D programming language