Skip to content

Instantly share code, notes, and snippets.

@ryanwinchester
Forked from bkilshaw/gist:3624901
Last active January 19, 2021 00:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanwinchester/f85b93de37676e01eb475887a5c6bc1c to your computer and use it in GitHub Desktop.
Save ryanwinchester/f85b93de37676e01eb475887a5c6bc1c to your computer and use it in GitHub Desktop.
MACVendors.com API :: V1 Code Samples
# cURL CLI (or shell script) example
curl -G "https://api.macvendors.com/v1/lookup/FC:FB:FB:01:FA:21" \
-H "Authorization: Bearer your-token-here"
<?php
// PHP using CURL example
$mac_address = "FC:FB:FB:01:FA:21";
$url = "https://api.macvendors.com/v1/lookup/" . urlencode($mac_address);
$token = 'your token here';
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer '.$token]);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$response = json_decode($response);
if (empty($response)) {
echo "Not Found";
} elseif ($data = $response->data) {
var_dump($data);
} elseif ($errors = $response->errors) {
var_dump($errors);
}
<?php
// PHP using Guzzle example
use GuzzleHttp\Client;
$client = new Client();
$mac_address = "FC:FB:FB:01:FA:21";
$url = "https://api.macvendors.com/v1/lookup/" . urlencode($mac_address);
$token = "your API token here";
$auth_header = ["Authorization" => "Bearer $token"];
$response = $client->get($url, ['headers' => $auth_header]);
if ($response->getStatusCode() != 200) {
echo "Nope";
} else {
$body = json_decode($response->getBody());
echo $data->organization_name;
// "Cisco Systems, Inc"
}
# Ruby example
require 'net/http'
mac_address = "FC:FB:FB:01:FA:21"
uri = URI("https://api.macvendors.com/v1/lookup/#{mac_address}")
token = "your API token"
req = Net::HTTP.Get.new(uri)
req["Authorization"] = "Bearer #{token}"
res = Net::HTTP.start(uri.hostname, uri.port) {|http|
http.request(req)
}
puts res.body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment