mirror of
https://github.com/MrUnknownDE/utools.git
synced 2026-04-23 07:53:45 +02:00
feat: Add initial frontend logic for network utilities (IP info, lookup, traceroute, port scan) and a backend route for MAC lookup.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
const express = require('express');
|
||||
const Sentry = require("@sentry/node");
|
||||
const macaddress = require('macaddress');
|
||||
const oui = require('oui');
|
||||
const pino = require('pino');
|
||||
const { isValidMacAddress } = require('../utils');
|
||||
|
||||
@@ -19,16 +19,17 @@ router.get('/', async (req, res) => {
|
||||
return res.status(400).json({ success: false, error: 'Invalid MAC address format provided.' });
|
||||
}
|
||||
|
||||
// Use 'oui' library to find vendor
|
||||
try {
|
||||
// Wrap the callback-based function in a Promise to use it with async/await
|
||||
const vendor = await new Promise((resolve, reject) => {
|
||||
macaddress.lookup(mac, (err, vendorString) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
resolve(vendorString);
|
||||
});
|
||||
});
|
||||
const ouiData = oui(mac);
|
||||
// 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;
|
||||
if (ouiData) {
|
||||
vendor = typeof ouiData === 'string' ? ouiData : ouiData.split('\n')[0];
|
||||
}
|
||||
|
||||
if (vendor) {
|
||||
logger.info({ requestIp, mac, vendor }, 'MAC lookup successful');
|
||||
@@ -37,11 +38,15 @@ router.get('/', async (req, res) => {
|
||||
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.' });
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error({ requestIp, mac, error: error.message }, 'MAC lookup failed');
|
||||
Sentry.captureException(error, { extra: { requestIp, mac } });
|
||||
res.status(500).json({ success: false, error: 'An unexpected error occurred during the MAC lookup.' });
|
||||
} catch (err) {
|
||||
// oui might throw on invalid input, though we validated it.
|
||||
throw err;
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error({ requestIp, mac, error: error.message }, 'MAC lookup failed');
|
||||
Sentry.captureException(error, { extra: { requestIp, mac } });
|
||||
res.status(500).json({ success: false, error: 'An unexpected error occurred during the MAC lookup.' });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user