The MAC Address Vendor search API lets you look up a manufacturer by MAC address with a simple HTTP GET request. GETplain text response http://searchmac.com/api/v2/MAC_ADDRESS - Replace
MAC_ADDRESS with a MAC address, for example e8:ba:70:c6:49:fa. - Successful lookup returns the vendor name as plain text. Unknown MACs return
Unknown. Invalid input returns WRONG_MAC_FORMAT.
Examples PHP <?php
class SearchMac {
const URL = 'http://searchmac.com/api/v2/';
protected $emptyNotice = 'Empty data received';
protected $formatNotice = 'Wrong MAC format';
/**
* Checks is MAC address valid?
*
* @param string $mac target mac address
*
* @return bool
*/
protected function checkMacFormat($mac) {
$mask = '/^[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}$/i';
if (preg_match($mask, $mac)) {
return (true);
} else {
return (false);
}
}
/**
* Returns vendor/manufacturer name by mac address
*
* @param string $mac mac address for vendor search
*
* @return string
*/
public function lookup($mac) {
if ($this->checkMacFormat($mac)) {
$rawdata = file_get_contents(self::URL . $mac);
if (!empty($rawdata)) {
$result = $rawdata;
} else {
$result = $this->emptyNotice;
}
} else {
$result = $this->formatNotice;
}
return ($result);
}
}
/*
* Example of usage
*/
$mac = 'e8:ba:70:c6:49:fa';
$look = new SearchMac();
$vendor = $look->lookup($mac);
print($vendor);
?>
Python import re
import requests
class SearchMac:
URL = 'http://searchmac.com/api/v2/'
def check_mac_format(self, mac):
return re.match(
r'^[a-f0-9]{2}(:[a-f0-9]{2}){5}$',
mac,
re.IGNORECASE
) is not None
def lookup(self, mac):
if not self.check_mac_format(mac):
return 'Wrong MAC format'
response = requests.get(self.URL + mac)
return response.text if response.text else 'Empty data received'
# Example of usage
mac = 'e8:ba:70:c6:49:fa'
look = SearchMac()
vendor = look.lookup(mac)
print(vendor)
JavaScript class SearchMac {
static URL = 'http://searchmac.com/api/v2/';
checkMacFormat(mac) {
return /^[a-f0-9]{2}(:[a-f0-9]{2}){5}$/i.test(mac);
}
async lookup(mac) {
if (!this.checkMacFormat(mac)) {
return 'Wrong MAC format';
}
const response = await fetch(SearchMac.URL + mac);
const text = await response.text();
return text ? text : 'Empty data received';
}
}
// Example of usage
const mac = 'e8:ba:70:c6:49:fa';
const look = new SearchMac();
look.lookup(mac).then(function (vendor) {
console.log(vendor);
});
Go package main
import (
"fmt"
"io"
"net/http"
"regexp"
)
const url = "http://searchmac.com/api/v2/"
type SearchMac struct{}
func (s SearchMac) checkMacFormat(mac string) bool {
matched, err := regexp.MatchString(`(?i)^[a-f0-9]{2}(:[a-f0-9]{2}){5}$`, mac)
if err != nil {
return false
}
return matched
}
func (s SearchMac) lookup(mac string) string {
if !s.checkMacFormat(mac) {
return "Wrong MAC format"
}
resp, err := http.Get(url + mac)
if err != nil {
return "Empty data received"
}
defer resp.Body.Close()
raw, err := io.ReadAll(resp.Body)
if err != nil || len(raw) == 0 {
return "Empty data received"
}
return string(raw)
}
func main() {
mac := "e8:ba:70:c6:49:fa"
look := SearchMac{}
vendor := look.lookup(mac)
fmt.Println(vendor)
}
Bash URL='http://searchmac.com/api/v2/'
check_mac_format() {
[[ "$1" =~ ^[a-fA-F0-9]{2}(:[a-fA-F0-9]{2}){5}$ ]]
}
lookup() {
local mac="$1"
local raw
if ! check_mac_format "$mac"; then
echo 'Wrong MAC format'
return
fi
raw="$(curl -sS "${URL}${mac}")"
if [ -n "$raw" ]; then
echo "$raw"
else
echo 'Empty data received'
fi
}
# Example of usage
mac='e8:ba:70:c6:49:fa'
vendor="$(lookup "$mac")"
echo "$vendor"
cURL # Vendor lookup, prints plain text
MAC='e8:ba:70:c6:49:fa'
curl -sS "http://searchmac.com/api/v2/${MAC}"
echo
|