-
-
Save ryanwinchester/f85b93de37676e01eb475887a5c6bc1c to your computer and use it in GitHub Desktop.
MACVendors.com API :: V1 Code Samples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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