Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.