feat: resolve recon device manufacturers locally
This commit is contained in:
@@ -1158,6 +1158,12 @@ OUI_VENDORS = {
|
||||
'FC633E': 'Google', 'FCF080': 'Apple',
|
||||
}
|
||||
|
||||
OUI_DATA_PATHS = [
|
||||
'/usr/share/nmap/nmap-mac-prefixes',
|
||||
'/usr/share/macchanger/OUI.list',
|
||||
]
|
||||
_oui_identity_cache = None
|
||||
|
||||
|
||||
def _oui_prefix(mac):
|
||||
"""'C8:9E:43:64:80:80' / 'C89E43648080' -> 'C89E43' (uppercase, no colons)."""
|
||||
@@ -1179,6 +1185,41 @@ def oui_vendor(mac):
|
||||
return OUI_VENDORS.get(prefix, 'Unknown')
|
||||
|
||||
|
||||
def oui_identity(mac):
|
||||
"""Resolve a MAC to a JSON-safe manufacturer identity."""
|
||||
global _oui_identity_cache
|
||||
prefix = _oui_prefix(mac)
|
||||
if prefix is None:
|
||||
return {'manufacturer': 'Unknown', 'model': None, 'oui': None,
|
||||
'source': 'unknown'}
|
||||
if int(prefix[1], 16) & 2:
|
||||
return {'manufacturer': 'Local/Randomized', 'model': None, 'oui': prefix,
|
||||
'source': 'local'}
|
||||
|
||||
if _oui_identity_cache is None:
|
||||
_oui_identity_cache = {}
|
||||
for path, source in zip(OUI_DATA_PATHS, ('nmap', 'macchanger')):
|
||||
try:
|
||||
with open(path, 'r') as data_file:
|
||||
for line in data_file:
|
||||
match = re.match(r'^\s*([0-9A-Fa-f:.-]+)\s+(.+)$', line)
|
||||
if not match:
|
||||
continue
|
||||
line_prefix = _oui_prefix(match.group(1))
|
||||
if line_prefix and line_prefix not in _oui_identity_cache:
|
||||
name = match.group(2).strip()
|
||||
if name:
|
||||
_oui_identity_cache[line_prefix] = (name, source)
|
||||
except (OSError, IOError):
|
||||
continue
|
||||
|
||||
manufacturer, source = _oui_identity_cache.get(
|
||||
prefix, (OUI_VENDORS.get(prefix, 'Unknown'),
|
||||
'builtin' if prefix in OUI_VENDORS else 'unknown'))
|
||||
return {'manufacturer': manufacturer, 'model': None, 'oui': prefix,
|
||||
'source': source}
|
||||
|
||||
|
||||
def band_of(freq):
|
||||
"""Channel frequency (MHz) -> '2.4' | '5' | '6' | '--'."""
|
||||
if freq is None:
|
||||
|
||||
Reference in New Issue
Block a user