mirror of
https://github.com/MrUnknownDE/utools.git
synced 2026-04-06 00:32:04 +02:00
try again mac-lookup
This commit is contained in:
@@ -21,4 +21,4 @@
|
||||
"pino-pretty": "^13.0.0",
|
||||
"whois-json": "^2.0.4"
|
||||
}
|
||||
}
|
||||
}
|
||||
39
backend/routes/macLookup.js
Normal file
39
backend/routes/macLookup.js
Normal file
@@ -0,0 +1,39 @@
|
||||
// backend/routes/macLookup.js
|
||||
const express = require('express');
|
||||
const Sentry = require("@sentry/node");
|
||||
const macaddress = require('macaddress');
|
||||
const pino = require('pino');
|
||||
const { isValidMacAddress } = require('../utils'); // Wir fügen diese neue Funktion hinzu
|
||||
|
||||
const logger = pino({ level: process.env.LOG_LEVEL || 'info' });
|
||||
const router = express.Router();
|
||||
|
||||
router.get('/', async (req, res) => {
|
||||
const macRaw = req.query.mac;
|
||||
const mac = typeof macRaw === 'string' ? macRaw.trim() : macRaw;
|
||||
const requestIp = req.ip || req.socket.remoteAddress;
|
||||
|
||||
logger.info({ requestIp, mac }, 'MAC lookup request received');
|
||||
|
||||
if (!isValidMacAddress(mac)) {
|
||||
logger.warn({ requestIp, mac }, 'Invalid MAC address for lookup');
|
||||
return res.status(400).json({ success: false, error: 'Invalid MAC address format provided.' });
|
||||
}
|
||||
|
||||
try {
|
||||
const vendor = await macaddress.lookup(mac);
|
||||
if (vendor) {
|
||||
logger.info({ requestIp, mac, vendor }, 'MAC lookup successful');
|
||||
res.json({ success: true, mac, vendor });
|
||||
} else {
|
||||
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.' });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@@ -1,6 +1,3 @@
|
||||
// backend/server.js
|
||||
// server.js
|
||||
// Load .env variables FIRST!
|
||||
require('dotenv').config();
|
||||
|
||||
// --- Sentry Initialisierung (GANZ OBEN, nach dotenv) ---
|
||||
@@ -35,6 +32,7 @@ const dnsLookupRoutes = require('./routes/dnsLookup');
|
||||
const whoisLookupRoutes = require('./routes/whoisLookup');
|
||||
const versionRoutes = require('./routes/version');
|
||||
const portScanRoutes = require('./routes/portScan');
|
||||
const macLookupRoutes = require('./routes/macLookup');
|
||||
|
||||
// --- Logger Initialisierung ---
|
||||
const logger = pino({
|
||||
@@ -97,6 +95,7 @@ app.use('/api/lookup', generalLimiter);
|
||||
app.use('/api/dns-lookup', generalLimiter);
|
||||
app.use('/api/whois-lookup', generalLimiter);
|
||||
app.use('/api/port-scan', generalLimiter);
|
||||
app.use('/api/mac-lookup', generalLimiter);
|
||||
|
||||
|
||||
// --- API Routes ---
|
||||
@@ -109,6 +108,7 @@ app.use('/api/dns-lookup', dnsLookupRoutes);
|
||||
app.use('/api/whois-lookup', whoisLookupRoutes);
|
||||
app.use('/api/version', versionRoutes);
|
||||
app.use('/api/port-scan', portScanRoutes);
|
||||
app.use('/api/mac-lookup', macLookupRoutes);
|
||||
|
||||
|
||||
// --- Sentry Error Handler ---
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// backend/utils.js
|
||||
const net = require('net'); // Node.js built-in module for IP validation
|
||||
const { spawn } = require('child_process');
|
||||
const pino = require('pino'); // Import pino for logging within utils if needed
|
||||
@@ -65,6 +66,20 @@ function isValidDomain(domain) {
|
||||
return domainRegex.test(domain.trim());
|
||||
}
|
||||
|
||||
/**
|
||||
* Validiert eine MAC-Adresse.
|
||||
* @param {string} mac - Die zu validierende MAC-Adresse.
|
||||
* @returns {boolean} True, wenn das Format gültig ist, sonst false.
|
||||
*/
|
||||
function isValidMacAddress(mac) {
|
||||
if (!mac || typeof mac !== 'string') {
|
||||
return false;
|
||||
}
|
||||
// This regex matches common MAC address formats (e.g., 00:1A:2B:3C:4D:5E, 00-1A-2B-3C-4D-5E, 001A2B3C4D5E)
|
||||
const macRegex = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$|^([0-9A-Fa-f]{12})$/;
|
||||
return macRegex.test(mac.trim());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Bereinigt eine IP-Adresse (z.B. entfernt ::ffff: Präfix von IPv4-mapped IPv6).
|
||||
@@ -302,6 +317,7 @@ module.exports = {
|
||||
isValidIp,
|
||||
isPrivateIp,
|
||||
isValidDomain,
|
||||
isValidMacAddress,
|
||||
getCleanIp,
|
||||
executeCommand,
|
||||
parsePingOutput,
|
||||
|
||||
@@ -88,11 +88,11 @@
|
||||
<h1>uTools Network Suite</h1> <!-- Name angepasst -->
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a href="index.html">IP Info & Tools</a></li> <!-- Angepasst -->
|
||||
<li><a href="index.html">IP Info & Tools</a></li>
|
||||
<li><a href="subnet-calculator.html">Subnetz Rechner</a></li>
|
||||
<li><a href="dns-lookup.html">DNS Lookup</a></li>
|
||||
<li><a href="whois-lookup.html">WHOIS Lookup</a></li>
|
||||
<!-- REMOVED: MAC Lookup Link -->
|
||||
<li><a href="mac-lookup.html">MAC Lookup</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
90
frontend/app/mac-lookup.html
Normal file
90
frontend/app/mac-lookup.html
Normal file
@@ -0,0 +1,90 @@
|
||||
// frontend/app/mac-lookup.html
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>MAC Vendor Lookup - uTools</title>
|
||||
<!-- Tailwind CSS Play CDN -->
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<!-- Eigene Styles -->
|
||||
<style>
|
||||
.loader {
|
||||
border: 4px solid rgba(168, 85, 247, 0.3);
|
||||
border-left-color: #a855f7;
|
||||
border-radius: 50%;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
@keyframes spin { to { transform: rotate(360deg); } }
|
||||
.result-pre {
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
font-family: monospace;
|
||||
background-color: #1f2937;
|
||||
color: #d1d5db;
|
||||
padding: 1rem;
|
||||
border-radius: 0.375rem;
|
||||
max-height: 400px;
|
||||
overflow-y: auto;
|
||||
font-size: 1.25rem; /* Larger font for the result */
|
||||
text-align: center;
|
||||
}
|
||||
nav ul { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 1rem; }
|
||||
nav a { color: #c4b5fd; text-decoration: none; white-space: nowrap; }
|
||||
nav a:hover { color: #a78bfa; text-decoration: underline; }
|
||||
header { background-color: #374151; padding: 1rem; margin-bottom: 1.5rem; border-radius: 0.5rem; display: flex; flex-direction: column; align-items: center; gap: 0.5rem; }
|
||||
@media (min-width: 768px) { header { flex-direction: row; justify-content: space-between; } }
|
||||
header h1 { font-size: 1.5rem; font-weight: bold; color: #e5e7eb; }
|
||||
.hidden { display: none; }
|
||||
</style>
|
||||
</head>
|
||||
<body class="bg-gray-900 text-gray-200 font-sans p-4 md:p-8">
|
||||
|
||||
<header>
|
||||
<h1>uTools Network Suite</h1>
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a href="index.html">IP Info & Tools</a></li>
|
||||
<li><a href="subnet-calculator.html">Subnetz Rechner</a></li>
|
||||
<li><a href="dns-lookup.html">DNS Lookup</a></li>
|
||||
<li><a href="whois-lookup.html">WHOIS Lookup</a></li>
|
||||
<li><a href="mac-lookup.html">MAC Lookup</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<div class="container mx-auto max-w-4xl bg-gray-800 rounded-lg shadow-xl p-6">
|
||||
|
||||
<h1 class="text-3xl font-bold mb-6 text-purple-400 text-center">MAC Address Vendor Lookup</h1>
|
||||
|
||||
<div class="mt-8 p-4 bg-gray-700 rounded">
|
||||
<div class="flex flex-col sm:flex-row gap-2 mb-4">
|
||||
<input type="text" id="mac-input" placeholder="Enter MAC address (e.g., 00:1A:2B:3C:4D:5E)"
|
||||
class="flex-grow px-3 py-2 bg-gray-800 border border-gray-600 rounded text-gray-200 focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-transparent font-mono">
|
||||
<button id="mac-lookup-button"
|
||||
class="bg-purple-600 hover:bg-purple-700 text-white font-bold py-2 px-4 rounded transition duration-150 ease-in-out">
|
||||
Find Vendor
|
||||
</button>
|
||||
</div>
|
||||
<div id="mac-lookup-error" class="text-red-400 mb-4 hidden"></div>
|
||||
<div id="mac-lookup-results-section" class="hidden mt-4 border-t border-gray-600 pt-4">
|
||||
<h3 class="text-lg font-semibold text-purple-300 mb-2">Vendor for: <span id="mac-lookup-query" class="font-mono text-purple-400"></span></h3>
|
||||
<div id="mac-lookup-loader" class="loader hidden mb-2 mx-auto"></div>
|
||||
<pre id="mac-lookup-output" class="result-pre"></pre>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="global-error" class="mt-6 p-4 bg-red-800 text-red-100 rounded hidden"></div>
|
||||
|
||||
<footer class="mt-8 pt-4 border-t border-gray-600 text-center text-xs text-gray-500">
|
||||
<p>© 2025 <a href="https://johanneskr.de" class="text-purple-400 hover:underline">Johannes Krüger</a></p>
|
||||
<p>Version: <span id="commit-sha" class="font-mono">loading...</span></p>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="mac-lookup.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
77
frontend/app/mac-lookup.js
Normal file
77
frontend/app/mac-lookup.js
Normal file
@@ -0,0 +1,77 @@
|
||||
// frontend/app/mac-lookup.js
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const macInput = document.getElementById('mac-input');
|
||||
const macLookupButton = document.getElementById('mac-lookup-button');
|
||||
const macLookupErrorEl = document.getElementById('mac-lookup-error');
|
||||
const macLookupResultsSection = document.getElementById('mac-lookup-results-section');
|
||||
const macLookupQueryEl = document.getElementById('mac-lookup-query');
|
||||
const macLookupLoader = document.getElementById('mac-lookup-loader');
|
||||
const macLookupOutputEl = document.getElementById('mac-lookup-output');
|
||||
const commitShaEl = document.getElementById('commit-sha');
|
||||
const globalErrorEl = document.getElementById('global-error');
|
||||
|
||||
const API_BASE_URL = '/api';
|
||||
|
||||
function showGlobalError(message) {
|
||||
if (!globalErrorEl) return;
|
||||
globalErrorEl.textContent = `Error: ${message}`;
|
||||
globalErrorEl.classList.remove('hidden');
|
||||
}
|
||||
|
||||
async function fetchVersionInfo() {
|
||||
if (!commitShaEl) return;
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}/version`);
|
||||
if (!response.ok) throw new Error(`Network response: ${response.statusText}`);
|
||||
const data = await response.json();
|
||||
commitShaEl.textContent = data.commitSha || 'unknown';
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch version info:', error);
|
||||
commitShaEl.textContent = 'error';
|
||||
}
|
||||
}
|
||||
|
||||
function displayMacResult(data, outputEl) {
|
||||
outputEl.textContent = data.vendor || 'No vendor found.';
|
||||
}
|
||||
|
||||
async function handleMacLookup() {
|
||||
const mac = macInput.value.trim();
|
||||
if (!mac) {
|
||||
macLookupErrorEl.textContent = 'Please enter a MAC address.';
|
||||
macLookupErrorEl.classList.remove('hidden');
|
||||
return;
|
||||
}
|
||||
|
||||
macLookupResultsSection.classList.remove('hidden');
|
||||
macLookupLoader.classList.remove('hidden');
|
||||
macLookupErrorEl.classList.add('hidden');
|
||||
macLookupOutputEl.textContent = '';
|
||||
macLookupQueryEl.textContent = mac;
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}/mac-lookup?mac=${encodeURIComponent(mac)}`);
|
||||
const data = await response.json();
|
||||
|
||||
if (!response.ok || !data.success) {
|
||||
throw new Error(data.error || `Request failed with status ${response.status}`);
|
||||
}
|
||||
|
||||
displayMacResult(data, macLookupOutputEl);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch MAC vendor:', error);
|
||||
macLookupErrorEl.textContent = `Error: ${error.message}`;
|
||||
macLookupErrorEl.classList.remove('hidden');
|
||||
macLookupOutputEl.textContent = '';
|
||||
} finally {
|
||||
macLookupLoader.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
fetchVersionInfo();
|
||||
macLookupButton.addEventListener('click', handleMacLookup);
|
||||
macInput.addEventListener('keypress', (event) => {
|
||||
if (event.key === 'Enter') handleMacLookup();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user