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.



Task

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"}}

 
(* build with ocamlfind ocamlopt -package netclient -linkpkg macaddr.ml -o macaddr *)
 
open Printf
open Nethttp_client.Convenience
open Unix
 
(* example vendors, including a nonsense one *)
 
let vendors = ["FF:FF:FF:67:07:BE"; "D4:F4:6F:C9:EF:8D"; "FC:FB:FB:01:FA:21"; "88:53:2E:67:07:BE"]
 
let get_vendor addr =
  sleep 3; (* built-in delay to handle rate-limiting at macvendors.com *)
 
  let client = http_get_message ("http://api.macvendors.com/" ^ addr) in
  match client # response_status_code with
  | 200 -> client # response_body # value
  | 404 -> "N/A"
  | _ -> "NULL"
 
let rec parse_vendors vendors =
  match vendors with
  | [] -> []
  | hd::tl -> get_vendor hd :: parse_vendors tl
 
let rec print_vendors vendor_list =
  match vendor_list with
  | [] -> ""
  | hd::tl -> printf "%s\n" hd; print_vendors tl
 
let main =
  let vendor_list = parse_vendors vendors in
  print_vendors vendor_list 
 
 
 
 