#!/usr/bin/env python3
import pickle
from binascii import unhexlify
from pathlib import Path
from urllib.request import urlopen
mac2vendor_file = Path.home() / ".config/mac2vendor.pickle"
def get_mac2vendor() -> dict[bytes, str]:
if mac2vendor_file.exists():
with mac2vendor_file.open("rb") as fd:
return pickle.load(fd)
url = "https://gitlab.com/wireshark/wireshark/-/raw/master/manuf"
lines = urlopen(url).read().decode().splitlines()
mac2vendor = {}
for row in lines:
if row.startswith("#") or not row.strip():
continue
mac, *_, company = row.strip().split("\t")
mac = unhexlify(mac.replace(":", "")[:6])
mac2vendor[mac] = company
with mac2vendor_file.open("wb") as fd:
pickle.dump(mac2vendor, fd)
return mac2vendor
def search(mac: str) -> str | None:
find_mac = unhexlify(mac.replace(":", "").replace("-", ""))
for mac_db, name in get_mac2vendor().items():
if find_mac.startswith(mac_db):
return name
return None
print(search("3c:7c:3f:c2:00:00"))
Comments
0 B
|👍
/👎