DeaD_EyE icon

mac2vendor from wireshark db

DeaD_EyE | PRO | 06/19/22 04:00:06 PM UTC | 0 ⭐ | 1448 👁️ | Never ⏰ | []
Python |

1.12 KB

|

None

|

0 👍

/

0 👎

#!/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

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎