fix(mac-vendor): 修复 OUI 数据库 key 格式不匹配导致永远查不到厂商
问题原因:
- oui.txt 中的 key 格式为 AABBCC(无冒号,6位十六进制)
- 代码中提取的 oui = mac[:8] 是 AA:BB:CC(带冒号,8字符)
- db.get(oui) 永远匹配不到,且回退的遍历逻辑在4万条字典上
每次查都全扫描,性能极差
解决方案:
- 提取 OUI 后去掉冒号再查询:oui.replace(':', '')
- 直接 db.get() 精确匹配,O(1) 时间复杂度
This commit is contained in:
@@ -86,15 +86,11 @@ class EnhancedScanService:
|
||||
# 1️⃣ 优先使用本地 OUI 数据库(免网络、高性能)
|
||||
db = _get_oui_db()
|
||||
if db:
|
||||
# 精确匹配 AA:BB:CC
|
||||
vendor = db.get(oui)
|
||||
# 数据库 key 是 AABBCC 格式(无冒号)
|
||||
oui_key = oui.replace(':', '')
|
||||
vendor = db.get(oui_key)
|
||||
if vendor:
|
||||
return vendor
|
||||
# 去掉冒号的格式匹配 AABBCC
|
||||
oui_no_colon = oui.replace(':', '')
|
||||
for prefix, v in db.items():
|
||||
if prefix == oui_no_colon:
|
||||
return v
|
||||
|
||||
# 2️⃣ 回退:mac_vendor_lookup 在线库
|
||||
if MAC_LOOKUP_AVAILABLE:
|
||||
|
||||
Reference in New Issue
Block a user