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

+150 -21
View File
@@ -1,8 +1,99 @@
// backend/deviceResolver.js
// ─────────────────────────────────────────────────────────────────────────────
// Heuristic resolution functions for discovered devices & metadata.
// IEEE OUI Manufacturer & Device Resolution (Deterministic, Non-Random)
// ─────────────────────────────────────────────────────────────────────────────
// Official IEEE OUI 24-bit prefix table (uppercase hex without colons)
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 +105,81 @@ 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];
// Check IEEE 802 Locally Administered Address (LAA) bit (bit 1 of first octet)
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,
+5 -4
View File
@@ -82,7 +82,7 @@ router.get('/', async (req, res) => {
]);
// Enrich devices with DeviceStat info (mac, os, manufacturer)
const { generateMacFromIp, resolveVendorFromIp, resolveOSFromIp, generateAutoLabel } = require('../deviceResolver');
const { generateMacFromIp, resolveVendorFromIp, resolveDeviceTypeFromIp, resolveOSFromIp, generateAutoLabel } = require('../deviceResolver');
const ips = topDevicesData.map(r => r._id).filter(Boolean);
const agentFilter = {};
@@ -97,9 +97,10 @@ router.get('/', async (req, res) => {
const ip = r._id;
const d = deviceMap[ip];
const mac = d?.mac_address && d.mac_address !== '-' ? d.mac_address : generateMacFromIp(ip);
const manufacturer = d?.manufacturer && d.manufacturer !== '-' && d.manufacturer !== 'Unknown' ? d.manufacturer : resolveVendorFromIp(ip);
const os = d?.os_label && d.os_label !== '-' && d.os_label !== 'Unknown' ? d.os_label : resolveOSFromIp(ip);
const label = d?.device_label && d.device_label !== '-' && d.device_label !== ip ? d.device_label : generateAutoLabel(ip, mac, manufacturer, 'Workstation');
const manufacturer = resolveVendorFromIp(ip, mac);
const type = resolveDeviceTypeFromIp(ip, mac);
const os = resolveOSFromIp(ip, mac);
const label = generateAutoLabel(ip, mac, manufacturer, type);
return {
src_ip: ip,
@@ -117,14 +117,9 @@ async function getLabelingHandler(req, res) {
const mac = item._id;
const customLabel = customLabelsMap[mac] || null;
const ip = item.ip_address || '-';
const type = item.device_type && item.device_type !== '-' && item.device_type !== 'Unknown' ? item.device_type : resolveDeviceTypeFromIp(ip);
const os = item.os_label && item.os_label !== '-' && item.os_label !== 'Unknown' ? item.os_label : resolveOSFromIp(ip);
const man = item.manufacturer && item.manufacturer !== '-' && item.manufacturer !== 'Unknown' ? item.manufacturer : resolveVendorFromIp(ip);
const baseLabel = item.device_label;
const defaultLabel = baseLabel && baseLabel !== '-' && baseLabel !== 'Unknown' && baseLabel !== 'Generic Client'
? baseLabel
: generateAutoLabel(ip, mac, man, type);
const man = resolveVendorFromIp(ip, mac);
const type = resolveDeviceTypeFromIp(ip, mac);
const defaultLabel = generateAutoLabel(ip, mac, man, type);
const agentUuid = item.agent_uuid || '';
const agentName = agentMap[agentUuid] || agentUuid || 'Unknown Agent';
+10 -15
View File
@@ -70,17 +70,12 @@ router.get('/devices', async (req, res) => {
const mapped = data.map(obj => {
const ip = obj.ip_address;
const mac = obj.mac_address && obj.mac_address !== '-' ? obj.mac_address : generateMacFromIp(ip);
const type = obj.device_type && obj.device_type !== '-' && obj.device_type !== 'Unknown' ? obj.device_type : resolveDeviceTypeFromIp(ip);
const os = obj.os_label && obj.os_label !== '-' && obj.os_label !== 'Unknown' ? obj.os_label : resolveOSFromIp(ip);
const rawMan = obj.manufacturer && obj.manufacturer !== '-' && obj.manufacturer !== 'Unknown' ? obj.manufacturer : null;
const isMismatchedWinVendor = os.startsWith('Windows') && (rawMan === 'Apple Inc.' || rawMan === 'Samsung Electronics');
const man = (rawMan && !isMismatchedWinVendor) ? rawMan : resolveVendorFromIp(ip);
const man = resolveVendorFromIp(ip, mac);
const type = resolveDeviceTypeFromIp(ip, mac);
const os = resolveOSFromIp(ip, mac);
const lastSeen = obj.last_seen || obj.timestamp || new Date().toISOString();
const rawLabel = customLabelsMap[mac] || obj.device_label;
const isStaleAutoLabel = isMismatchedWinVendor && rawLabel && (rawLabel.startsWith('Apple ') || rawLabel.startsWith('Samsung '));
const baseLabel = isStaleAutoLabel ? null : rawLabel;
const baseLabel = customLabelsMap[mac] || (obj.device_label && !obj.device_label.includes('Workstation / Laptop') ? obj.device_label : null);
const label = baseLabel && baseLabel !== '-' && baseLabel !== 'Unknown' && baseLabel !== 'Generic Client'
? baseLabel
: generateAutoLabel(ip, mac, man, type);
@@ -128,7 +123,7 @@ router.get('/mac-bandwidth', async (req, res) => {
upload: 1,
ip: 1,
label: 1,
manufacturer: { $ifNull: [ '$manufacturer', 'Intel Corporation' ] },
manufacturer: 1,
total: { $add: [ '$download', '$upload' ] },
_id: 0
}},
@@ -138,7 +133,7 @@ router.get('/mac-bandwidth', async (req, res) => {
const data = raw.map(d => {
const mac = d.mac_address && d.mac_address !== '-' ? d.mac_address : generateMacFromIp(d.ip);
const man = d.manufacturer && d.manufacturer !== '-' && d.manufacturer !== 'Unknown' ? d.manufacturer : resolveVendorFromIp(d.ip);
const man = resolveVendorFromIp(d.ip, mac);
return {
...d,
mac_address: mac,
@@ -238,10 +233,10 @@ router.get('/security-devices', async (req, res) => {
const obj = d.latestDoc;
const ip = obj.ip_address;
const mac = obj.mac_address && obj.mac_address !== '-' ? obj.mac_address : generateMacFromIp(ip);
const type = obj.device_type && obj.device_type !== '-' && obj.device_type !== 'Unknown' ? obj.device_type : resolveDeviceTypeFromIp(ip);
const os = obj.os_label && obj.os_label !== '-' && obj.os_label !== 'Unknown' ? obj.os_label : resolveOSFromIp(ip);
const man = obj.manufacturer && obj.manufacturer !== '-' && obj.manufacturer !== 'Unknown' ? obj.manufacturer : resolveVendorFromIp(ip);
const baseLabel = customLabelsMap[mac] || obj.device_label;
const man = resolveVendorFromIp(ip, mac);
const type = resolveDeviceTypeFromIp(ip, mac);
const os = resolveOSFromIp(ip, mac);
const baseLabel = customLabelsMap[mac];
const label = baseLabel && baseLabel !== '-' && baseLabel !== 'Unknown' && baseLabel !== 'Generic Client'
? baseLabel
: generateAutoLabel(ip, mac, man, type);
+7 -9
View File
@@ -174,18 +174,16 @@ module.exports = async function deviceDetailsHandler(req, res, helpers) {
}
// ── Device metadata ───────────────────────────────────────────────────────
const targetMac = device?.mac_address || mac || generateMacFromIp(ip);
const type = (device?.device_type && !['−', 'Unknown', '-'].includes(device.device_type)) ? device.device_type : resolveDeviceTypeFromIp(ip);
const os = (device?.os_label && !['−', 'Unknown', '-'].includes(device.os_label)) ? device.os_label : resolveOSFromIp(ip);
const rawMan = (device?.manufacturer && !['−', 'Unknown', '-'].includes(device.manufacturer)) ? device.manufacturer : null;
const isWinMismatch = os.startsWith('Windows') && (rawMan === 'Apple Inc.' || rawMan === 'Samsung Electronics');
const man = (rawMan && !isWinMismatch) ? rawMan : resolveVendorFromIp(ip);
const flowMac = flowsQuery.find(f => f.src_ip === ip && f.src_mac && !f.src_mac.startsWith('00:16:3e:'))?.src_mac;
const rawDevMac = device?.mac_address && !device.mac_address.startsWith('00:16:3e:') ? device.mac_address : null;
const targetMac = rawDevMac || flowMac || mac || device?.mac_address || generateMacFromIp(ip);
const man = resolveVendorFromIp(ip, targetMac);
const type = resolveDeviceTypeFromIp(ip, targetMac);
const os = resolveOSFromIp(ip, targetMac);
const lastSeen = device?.last_seen || device?.timestamp || new Date().toISOString();
const customLabelDoc = await CustomDeviceLabel.findOne({ mac_address: targetMac }).lean();
const rawBase = customLabelDoc?.device_label || device?.device_label;
const isStaleLbl = isWinMismatch && rawBase && (rawBase.startsWith('Apple ') || rawBase.startsWith('Samsung '));
const baseLabel = isStaleLbl ? null : rawBase;
const baseLabel = customLabelDoc?.device_label;
const finalLabel = baseLabel && !['−', 'Unknown', 'Generic Client', '-'].includes(baseLabel)
? baseLabel : generateAutoLabel(ip, targetMac, man, type);
+5 -4
View File
@@ -78,7 +78,7 @@ async function deviceBreakdownByDomain(type, value, base) {
// ─── Helper: enrich IP rows with DeviceStat info ───────────────────────────────
async function enrichWithDeviceStat(ipRows, agentFilter) {
const { generateMacFromIp, resolveVendorFromIp, resolveOSFromIp, generateAutoLabel } = require('../deviceResolver');
const { generateMacFromIp, resolveVendorFromIp, resolveDeviceTypeFromIp, resolveOSFromIp, generateAutoLabel } = require('../deviceResolver');
const ips = ipRows.map(r => r._id).filter(Boolean);
const devices = await DeviceStat.find({ ip_address: { $in: ips }, ...agentFilter }).lean();
const deviceMap = {};
@@ -87,9 +87,10 @@ async function enrichWithDeviceStat(ipRows, agentFilter) {
const ip = r._id;
const d = deviceMap[ip];
const mac = d?.mac_address && d.mac_address !== '-' ? d.mac_address : generateMacFromIp(ip);
const manufacturer = d?.manufacturer && d.manufacturer !== '-' && d.manufacturer !== 'Unknown' ? d.manufacturer : resolveVendorFromIp(ip);
const os = d?.os_label && d.os_label !== '-' && d.os_label !== 'Unknown' ? d.os_label : resolveOSFromIp(ip);
const label = d?.device_label && d.device_label !== '-' && d.device_label !== ip ? d.device_label : generateAutoLabel(ip, mac, manufacturer, 'Workstation');
const manufacturer = resolveVendorFromIp(ip, mac);
const type = resolveDeviceTypeFromIp(ip, mac);
const os = resolveOSFromIp(ip, mac);
const label = generateAutoLabel(ip, mac, manufacturer, type);
return {
src_ip: ip,
device_label: label,
+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,