fix(devices): resolve real hardware vendor from MAC IEEE OUI instead of random IP hash

This commit is contained in:
ypratama committed 2026-11-09 13:32:51 +07:00
1 parent 0708d36d51
commit 11b89a9030
8 files changed
+346 -86

No files matched your search

+18 -4
View File
@@ -68,12 +68,26 @@ async function collectDevicesAndApps(agentUuid, timestamp, SITE_UUID, backone, l
const allowedSubnets = await getAllowedSubnets(agentUuid);
if (devices && devices.length > 0) {
// Look up known real MAC addresses from Flow collection for this agent
const ips = devices.map(d => d.ip_address).filter(Boolean);
const recentFlows = await Flow.aggregate([
{ $match: { agent_uuid: agentUuid, src_ip: { $in: ips }, src_mac: { $ne: null, $nin: ['-', 'Unknown'] } } },
{ $sort: { timestamp: -1 } },
{ $group: { _id: '$src_ip', mac: { $first: '$src_mac' } } }
]).catch(() => []);
for (const rf of recentFlows) {
if (rf._id && rf.mac && !rf.mac.startsWith('00:16:3e:')) {
ipToMacMap[rf._id] = rf.mac.toLowerCase();
}
}
const devDocs = devices.map(d => {
const ip = d.ip_address;
const mac = d.mac_address && d.mac_address !== '-' && d.mac_address !== 'Unknown' ? d.mac_address : generateMacFromIp(ip);
const manufacturer = d.manufacturer && d.manufacturer !== '-' && d.manufacturer !== 'Unknown' ? d.manufacturer : resolveVendorFromIp(ip);
const device_type = d.device_type && d.device_type !== '-' && d.device_type !== 'Unknown' ? d.device_type : resolveDeviceTypeFromIp(ip);
const os_label = d.os_label && d.os_label !== '-' && d.os_label !== 'Unknown' ? d.os_label : resolveOSFromIp(ip);
const rawMac = d.mac_address && d.mac_address !== '-' && d.mac_address !== 'Unknown' ? d.mac_address : null;
const mac = rawMac || ipToMacMap[ip] || generateMacFromIp(ip);
const manufacturer = d.manufacturer && d.manufacturer !== '-' && d.manufacturer !== 'Unknown' ? d.manufacturer : resolveVendorFromIp(ip, mac);
const device_type = d.device_type && d.device_type !== '-' && d.device_type !== 'Unknown' ? d.device_type : resolveDeviceTypeFromIp(ip, mac);
const os_label = d.os_label && d.os_label !== '-' && d.os_label !== 'Unknown' ? d.os_label : resolveOSFromIp(ip, mac);
const device_label = d.device_label && d.device_label !== '-' && d.device_label !== ip ? d.device_label : generateAutoLabel(ip, mac, manufacturer, device_type);
if (ip && mac) ipToMacMap[ip] = mac;
+148 -21
View File
@@ -1,8 +1,98 @@
// proxy/deviceResolver.js
// ─────────────────────────────────────────────────────────────────────────────
// Heuristic resolution functions for discovered devices & metadata.
// IEEE OUI Manufacturer & Device Resolution (Deterministic, Non-Random)
// ─────────────────────────────────────────────────────────────────────────────
const IEEE_OUI_MAP = {
// MikroTik / Routerboard
'C4AD34': 'MikroTik (Routerboard.com)',
'04F41C': 'MikroTik (Routerboard.com)',
'D4CA6D': 'MikroTik (Routerboard.com)',
'E48D8C': 'MikroTik (Routerboard.com)',
'4C5E0C': 'MikroTik (Routerboard.com)',
'64D154': 'MikroTik (Routerboard.com)',
'CC2DE0': 'MikroTik (Routerboard.com)',
'B869F4': 'MikroTik (Routerboard.com)',
'744D28': 'MikroTik (Routerboard.com)',
'085531': 'MikroTik (Routerboard.com)',
'18FD74': 'MikroTik (Routerboard.com)',
'2CC81B': 'MikroTik (Routerboard.com)',
'488F5A': 'MikroTik (Routerboard.com)',
'48A98A': 'MikroTik (Routerboard.com)',
'789A18': 'MikroTik (Routerboard.com)',
'DC2C6E': 'MikroTik (Routerboard.com)',
// Ruijie Networks
'C0A476': 'Ruijie Networks Co., Ltd.',
'E05D54': 'Ruijie Networks Co., Ltd.',
'58696C': 'Ruijie Networks Co., Ltd.',
'00749C': 'Ruijie Networks Co., Ltd.',
'300D9E': 'Ruijie Networks Co., Ltd.',
'707990': 'Ruijie Networks Co., Ltd.',
'ECB970': 'Ruijie Networks Co., Ltd.',
// Cisco Systems
'00D6FE': 'Cisco Systems, Inc.',
'001B54': 'Cisco Systems, Inc.',
'002414': 'Cisco Systems, Inc.',
'58AC78': 'Cisco Systems, Inc.',
'F872EA': 'Cisco Systems, Inc.',
// Hikvision (CCTV / NVR)
'3C1BF8': 'Hikvision Digital Technology',
'88DE39': 'Hikvision Digital Technology',
'E8A0ED': 'Hikvision Digital Technology',
'2857BE': 'Hikvision Digital Technology',
'4419B6': 'Hikvision Digital Technology',
'54C415': 'Hikvision Digital Technology',
'BCAD28': 'Hikvision Digital Technology',
'C056E3': 'Hikvision Digital Technology',
// Seiko Epson (Printers)
'50579C': 'Seiko Epson Corporation',
'F82551': 'Seiko Epson Corporation',
'0026AB': 'Seiko Epson Corporation',
'64EB8C': 'Seiko Epson Corporation',
'AC1826': 'Seiko Epson Corporation',
// PC / Motherboard / NIC Vendors
'04D4C4': 'ASUSTek Computer Inc.',
'3C7C3F': 'ASUSTek Computer Inc.',
'F02F74': 'ASUSTek Computer Inc.',
'2CFDA1': 'ASUSTek Computer Inc.',
'A85E45': 'ASUSTek Computer Inc.',
'2CF05D': 'Micro-Star INT\'L CO., LTD. (MSI)',
'00D861': 'Micro-Star INT\'L CO., LTD. (MSI)',
'D8BBC1': 'Micro-Star INT\'L CO., LTD. (MSI)',
'309C23': 'Micro-Star INT\'L CO., LTD. (MSI)',
'085BD6': 'Intel Corporate',
'001B21': 'Intel Corporate',
'3C970E': 'Intel Corporate',
'8C8D28': 'Intel Corporate',
'A434D9': 'Intel Corporate',
'DCFB48': 'Intel Corporate',
'F8633F': 'Intel Corporate',
'14B5CD': 'Liteon Technology Corporation',
'3052CB': 'Liteon Technology Corporation',
'E8B1FC': 'Liteon Technology Corporation',
'60BEB4': 'S-Bluetech Co., Limited',
'0C9A42': 'FN-LINK Technology Limited',
'782288': 'Shenzhen Bilian Electronic Co., Ltd.',
// Mobile / Consumer
'4C6F9C': 'OPPO Mobile Telecommunications',
'A43BFA': 'OPPO Mobile Telecommunications',
'E8BBA8': 'OPPO Mobile Telecommunications',
'2C5BB8': 'OPPO Mobile Telecommunications',
// Virtualization
'00163E': 'Unidentified (L3 Routed)',
'005056': 'VMware, Inc.',
'000C29': 'VMware, Inc.',
'00155D': 'Microsoft Hyper-V',
'525400': 'QEMU / KVM Virtual NIC',
};
function generateMacFromIp(ip) {
if (!ip) return '00:16:3e:00:11:22';
let hash = 0;
@@ -14,43 +104,80 @@ function generateMacFromIp(ip) {
return `00:16:3e:${hex.substring(0, 2)}:${hex.substring(2, 4)}:${hex.substring(4, 6)}`;
}
function resolveVendorFromIp(ip) {
if (!ip) return 'Intel Corporation';
if (ip.startsWith('10.6.30.') || ip.startsWith('10.250.')) return 'Supermicro / Dell Inc.';
if (ip.startsWith('10.6.10.') || ip.startsWith('10.6.11.')) return 'Cisco Systems, Inc.';
if (ip.startsWith('192.168.')) return 'TP-Link Corporation';
let hash = 0;
for (let i = 0; i < ip.length; i++) hash = (hash << 5) - hash + ip.charCodeAt(i);
const vendors = ['Intel Corporation', 'Asustek Computer Inc.', 'Dell Inc.', 'Hewlett Packard', 'Lenovo'];
return vendors[Math.abs(hash) % vendors.length];
function resolveVendorFromMac(mac) {
if (!mac || typeof mac !== 'string' || mac === '-' || mac === 'Unknown') return null;
const clean = mac.replace(/[^0-9a-fA-F]/g, '').toUpperCase();
if (clean.length < 6) return null;
const oui = clean.slice(0, 6);
if (oui === '00163E') return 'Unidentified (L3 Routed)';
if (IEEE_OUI_MAP[oui]) return IEEE_OUI_MAP[oui];
const firstByte = parseInt(oui.slice(0, 2), 16);
if (!isNaN(firstByte) && (firstByte & 0x02) !== 0) {
return 'Private / Randomized MAC';
}
return 'Unknown Vendor';
}
function resolveDeviceTypeFromIp(ip) {
if (!ip) return 'Workstation';
function resolveVendorFromIp(ip, mac = null) {
const fromMac = resolveVendorFromMac(mac);
if (fromMac) return fromMac;
return 'Unidentified (L3 Routed)';
}
function resolveDeviceTypeFromIp(ip, mac = null) {
const vendor = resolveVendorFromMac(mac) || '';
if (vendor.includes('Hikvision')) return 'IP Camera / NVR';
if (vendor.includes('Epson')) return 'Network Printer';
if (vendor.includes('Ruijie')) return 'Switch / Access Point';
if (vendor.includes('Cisco')) return 'Gateway / Router';
if (vendor.includes('OPPO')) return 'Mobile / Smartphone';
if (vendor === 'Private / Randomized MAC') return 'Mobile / Wi-Fi Client';
if (!ip) return 'Workstation / Laptop';
if (ip.endsWith('.1') || ip.endsWith('.254')) return 'Gateway / Router';
if (ip.startsWith('10.6.30.')) return 'Database Server';
if (ip.startsWith('10.250.')) return 'Core Network Node';
if (ip.startsWith('10.6.12.')) return 'Finance Workstation';
return 'Workstation / Laptop';
}
function resolveOSFromIp(ip) {
if (!ip) return 'Windows 11';
if (ip.startsWith('10.6.30.') || ip.startsWith('10.250.')) return 'Linux (Ubuntu Server 24.04)';
if (ip.startsWith('10.6.12.')) return 'Windows 11 Enterprise';
if (ip.startsWith('192.168.')) return 'iOS / Android';
return 'Windows 11 Pro';
function resolveOSFromIp(ip, mac = null) {
const vendor = resolveVendorFromMac(mac) || '';
if (vendor.includes('Hikvision')) return 'Embedded Linux (NVR/IPC)';
if (vendor.includes('Epson')) return 'Epson Printer Firmware';
if (vendor.includes('Ruijie')) return 'Ruijie RGOS';
if (vendor.includes('Cisco')) return 'Cisco IOS';
if (vendor.includes('OPPO')) return 'Android (ColorOS)';
if (vendor.includes('MikroTik') && ip && (ip.endsWith('.1') || ip.endsWith('.254'))) {
return 'MikroTik RouterOS';
}
if (!ip) return 'Windows / Linux';
if (ip.startsWith('10.6.30.') || ip.startsWith('10.250.')) return 'Linux Server';
if (ip.startsWith('192.168.')) return 'Android / iOS / Windows';
return 'Windows / Linux';
}
function generateAutoLabel(ip, mac, manufacturer, deviceType) {
const brand = manufacturer && manufacturer !== '-' && manufacturer !== 'Unknown' ? manufacturer.split(' ')[0] : '';
const type = deviceType && deviceType !== '-' && deviceType !== 'Unknown' ? deviceType : 'Device';
const suffix = ip ? ip.split('.').slice(-2).join('.') : (mac ? mac.split(':').slice(-2).join(':') : 'Node');
return brand ? `${brand} ${type} (${suffix})` : `${type} (${suffix})`;
if (
!manufacturer ||
manufacturer === '-' ||
manufacturer === 'Unknown' ||
manufacturer === 'Unknown Vendor' ||
manufacturer.startsWith('Unidentified') ||
manufacturer.startsWith('Private /') ||
(manufacturer.includes('MikroTik') && type === 'Workstation / Laptop')
) {
return `${type} (${suffix})`;
}
const brand = manufacturer.split(' ')[0];
return `${brand} ${type} (${suffix})`;
}
module.exports = {
IEEE_OUI_MAP,
generateMacFromIp,
resolveVendorFromMac,
resolveVendorFromIp,
resolveDeviceTypeFromIp,
resolveOSFromIp,