From 5d462431d44e7367e321b08e66cf23b702b07e3a Mon Sep 17 00:00:00 2001 From: Douglas Barone Date: Mon, 21 Dec 2020 10:17:25 -0400 Subject: [PATCH] Added hostname mocking --- server/src/lib/wifiDevices.js | 9 ++++++++- server/src/utils/ouiFinder.js | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/server/src/lib/wifiDevices.js b/server/src/lib/wifiDevices.js index ce44c4d..4643c71 100644 --- a/server/src/lib/wifiDevices.js +++ b/server/src/lib/wifiDevices.js @@ -60,6 +60,13 @@ async function forceUserDisconnect(mac) { ) } +function mockHostName({ mac, oui }) { + const [shortOui] = oui?.split(' ') + const clearMac = mac?.replaceAll(':', '') + + return `${shortOui}_${clearMac}` +} + async function updateDB(onlineDevices) { for (const device of onlineDevices) { if (!device.user) await forceUserDisconnect(device.mac) @@ -80,7 +87,7 @@ async function updateDB(onlineDevices) { }, update: { ...device, - hostname: device.hostname || device.mac, + hostname: device.hostname || mockHostName(device), user } }) diff --git a/server/src/utils/ouiFinder.js b/server/src/utils/ouiFinder.js index 2ed7984..38719b5 100644 --- a/server/src/utils/ouiFinder.js +++ b/server/src/utils/ouiFinder.js @@ -2,8 +2,8 @@ import oui from 'oui' function ouiFinder(mac) { const addrOui = oui(mac) - - if (!mac || !addrOui) return 'Indeterminado' + + if (!mac || !addrOui) return '' return addrOui.split('\n')[0] }