How to handle unknown Vendors for mac-vendor-lookup

Viewed 618

I would like to create a dict based on MAC addresses and vendor, using the mac-vendor-lookup library. My code:

dicts = {}
for index, value in mac_series.items():
    try:
        vendor = mac.lookup(value)
    except KeyError as e:
        print(f"Error: {e}")
        vendor = "UNKNOWN"
    dicts[value] = vendor

This works fine, because I handle KeyErrors in the try/except. However I'd like to know why I get a KeyError in the first place, when the Mac addresses all follow a certain format. So I get mostly vendors coming back, but sometimes the occasional "UNKNOWN". Is this an issue with an outdated lookup (despite using the latest pip package)?

1 Answers

As per the library, you will need to update the vendors list often using the following code

mac.update_vendors()  # <- This can take a few seconds for the download

Also sometimes the Mac address you are trying to lookup for is a fake one, so there will be no results for it, better paste the mac address you are trying with.


Another alternative you can download mac address lookup XML file and build your own lookup code on top of it, but you will need to update it regularly.

Related