Skip to content

Instantly share code, notes, and snippets.

@bkilshaw
Last active November 15, 2023 19:22
Show Gist options
  • Save bkilshaw/3624901 to your computer and use it in GitHub Desktop.
Save bkilshaw/3624901 to your computer and use it in GitHub Desktop.
MACVendors.com API :: PHP GET Example
<?php
$mac_address = "FC:FB:FB:01:FA:21";
$url = "https://api.macvendors.com/" . urlencode($mac_address);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if($response) {
echo "Vendor: $response";
} else {
echo "Not Found";
}
?>
@sporkman
Copy link

crappy shell example:

fruitcake:~ spork$ cat mac.sh
#!/bin/bash

# encode from here: https://stackoverflow.com/questions/296536/how-to-urlencode-data-for-curl-command
rawurlencode() {
  local string="${1}"
  local strlen=${#string}
  local encoded=""
  local pos c o

  for (( pos=0 ; pos<strlen ; pos++ )); do
     c=${string:$pos:1}
     case "$c" in
        [-_.~a-zA-Z0-9] ) o="${c}" ;;
        * )               printf -v o '%%%02x' "'$c"
     esac
     encoded+="${o}"
  done
  ENC="${encoded}"   #+or echo the result (EASIER)... or both... :p
}

OUI=${1:?'bad mac'}
rawurlencode $OUI
echo -n "MAC $OUI Vendor: "
curl http://api.macvendors.com/$ENC

@ecwright3
Copy link

#!/usr/bin/python
import requests

macaddress = "FC-A1-3E-2A-1C-33"
r = requests.get(url="http://api.macvendors.com/%s" %macaddress)
print(r.text)

@Pablohn26
Copy link

Now this gist get a 301 due to the use of HTTP.

To get this gist working, you have to change on line 4 http by https

@ehaupt
Copy link

ehaupt commented Sep 26, 2020

A python solution using netaddr:

#!/usr/bin/env python

import sys
from netaddr import EUI

print(EUI(sys.argv[1]).oui.registration().org)

Accepts multiple known mac formats.

$ maclookup.py FC-A1-3E-2A-1C-33
Samsung Electronics Co.,Ltd
$ ./maclookup.py FC:A1:3E:2A:1C:33
Samsung Electronics Co.,Ltd
$ ./maclookup.py fc:a1:3e:2a:1c:33
Samsung Electronics Co.,Ltd
$ ./maclookup.py fca13e2a1c33
Samsung Electronics Co.,Ltd

@buananetpbun
Copy link

can use with javascript?

@keslar
Copy link

keslar commented Nov 15, 2023

Here is a PowerShell version:

mac_address = "FC:FB:FB:01:FA:21"
$url    = "https://api.macvendors.com/$([URI]::EscapeUriString($mac_address))"
$response = Invoke-RestMethod -Method GET -Uri $url
if ( $null -ne $response ) {
   "Vendor: $($response)"
} else {
   "Vendor not found for the MAC address $($mac_address)."
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment