mirror of
https://github.com/MrUnknownDE/utools.git
synced 2026-04-26 17:43:45 +02:00
feat: add MAC address lookup API endpoint and backend dependencies
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const Sentry = require("@sentry/node");
|
const Sentry = require("@sentry/node");
|
||||||
const oui = require('oui');
|
|
||||||
const pino = require('pino');
|
const pino = require('pino');
|
||||||
const { isValidMacAddress } = require('../utils');
|
const { isValidMacAddress } = require('../utils');
|
||||||
|
|
||||||
@@ -21,10 +20,12 @@ router.get('/', async (req, res) => {
|
|||||||
|
|
||||||
// Use 'oui' library to find vendor
|
// Use 'oui' library to find vendor
|
||||||
try {
|
try {
|
||||||
|
// Dynamic import for ESM-only 'oui' module
|
||||||
|
const ouiModule = await import('oui');
|
||||||
|
const oui = ouiModule.default;
|
||||||
|
|
||||||
const ouiData = oui(mac);
|
const ouiData = oui(mac);
|
||||||
// oui returns a string (Vendor Name) or null if not found
|
// oui returns a string (Vendor Name) or null if not found
|
||||||
// Sometimes it returns an object? The documentation says it returns the organization name string.
|
|
||||||
// Let's handle both just in case, but usually it's a string or null.
|
|
||||||
|
|
||||||
let vendor = null;
|
let vendor = null;
|
||||||
if (ouiData) {
|
if (ouiData) {
|
||||||
@@ -38,10 +39,6 @@ router.get('/', async (req, res) => {
|
|||||||
logger.info({ requestIp, mac }, 'MAC address not found in OUI database');
|
logger.info({ requestIp, mac }, 'MAC address not found in OUI database');
|
||||||
res.status(404).json({ success: false, error: 'Vendor not found for this MAC address.' });
|
res.status(404).json({ success: false, error: 'Vendor not found for this MAC address.' });
|
||||||
}
|
}
|
||||||
} catch (err) {
|
|
||||||
// oui might throw on invalid input, though we validated it.
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error({ requestIp, mac, error: error.message }, 'MAC lookup failed');
|
logger.error({ requestIp, mac, error: error.message }, 'MAC lookup failed');
|
||||||
Sentry.captureException(error, { extra: { requestIp, mac } });
|
Sentry.captureException(error, { extra: { requestIp, mac } });
|
||||||
|
|||||||
Reference in New Issue
Block a user