Refactor MAC vendor lookup to streamline vendor retrieval and improve debug logging
This commit is contained in:
parent
45b33dc48b
commit
1a884c8085
1 changed files with 6 additions and 12 deletions
18
listener.py
18
listener.py
|
@ -323,9 +323,7 @@ def main():
|
||||||
|
|
||||||
def get_mac_vendor(mac):
|
def get_mac_vendor(mac):
|
||||||
prefix = mac.upper()[0:8].replace(":", "-")
|
prefix = mac.upper()[0:8].replace(":", "-")
|
||||||
print(f"[DEBUG] Looking up prefix: {prefix}")
|
|
||||||
if prefix in vendor_cache:
|
if prefix in vendor_cache:
|
||||||
print(f"[DEBUG] Cached hit: {vendor_cache[prefix]}")
|
|
||||||
return vendor_cache[prefix]
|
return vendor_cache[prefix]
|
||||||
try:
|
try:
|
||||||
if not os.path.exists("oui.txt"):
|
if not os.path.exists("oui.txt"):
|
||||||
|
@ -335,16 +333,12 @@ def get_mac_vendor(mac):
|
||||||
urllib.request.urlretrieve(url, "oui.txt")
|
urllib.request.urlretrieve(url, "oui.txt")
|
||||||
with open("oui.txt", "r", encoding="utf-8", errors="ignore") as f:
|
with open("oui.txt", "r", encoding="utf-8", errors="ignore") as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
print(repr(line))
|
if "(hex)" in line and prefix in line:
|
||||||
if line.strip().endswith("(hex)"):
|
parts = line.strip().split()
|
||||||
parts = line.split()
|
if len(parts) >= 3 and parts[0] == prefix and parts[1] == "(hex)":
|
||||||
if len(parts) >= 3:
|
vendor = " ".join(parts[2:]).strip()
|
||||||
print(f"[DEBUG] Checking line: {parts}")
|
vendor_cache[prefix] = vendor
|
||||||
if parts[0] == prefix:
|
return vendor
|
||||||
vendor = " ".join(parts[2:]).replace("(hex)", "").strip()
|
|
||||||
vendor_cache[prefix] = vendor
|
|
||||||
print(f"[DEBUG] Vendor found: {vendor}")
|
|
||||||
return vendor
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[ERROR] Vendor lookup failed: {e}")
|
print(f"[ERROR] Vendor lookup failed: {e}")
|
||||||
vendor_cache[prefix] = "Unknown"
|
vendor_cache[prefix] = "Unknown"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue