Files
MyIP/common/mac-input.js
T
jason5ng32andClaude Opus 5.5 7a52e8acea Feat(mac): answer MAC Lookup from the local IEEE registries
MAC Lookup no longer calls maclookup.app. The five public IEEE registries
(MA-L, MA-M, MA-S, IAB, CID) are a new `oui` dataset row — no key needed,
published as downloaded, refused below per-registry row floors — and
common/oui-db.js answers the longest assignment covering a query, the group
bit masked so a multicast address resolves to the block it derives from.
The country is read off the end of the registered address.

?mac= now takes a vendor prefix as well as a full address (6–12 hex digits,
colon / hyphen / dotted / bare), parsed by common/mac-input.js, which the
form shares. An address no block covers is still answered, with its flags.
The route is gated by requireOfflineData while the registries download at
boot. MAC_LOOKUP_API_KEY is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 11:21:12 +08:00

23 lines
890 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// MAC Lookup query parsing, shared by the /api/macchecker handler and the
// MacChecker form (via frontend/utils/mac-input.js). A query is a full
// 48-bit address or any leading part of one, down to a 24-bit vendor prefix,
// in the usual notations: colon / hyphen pairs, Cisco dotted quads, or bare
// hex.
export const MAC_HEX_LENGTH = 12;
export const MAC_PREFIX_MIN_HEX = 6;
// Separators accepted between hex digits: `:` `-` `.` and whitespace.
const SEPARATORS = /[\s:.-]/g;
/**
* Upper-case bare hex of a full address or a prefix (6–12 hex digits), or
* null for anything else.
*/
export const normalizeMacQuery = (input) => {
if (typeof input !== 'string') return null;
const hex = input.replace(SEPARATORS, '').toUpperCase();
if (hex.length < MAC_PREFIX_MIN_HEX || hex.length > MAC_HEX_LENGTH) return null;
return /^[0-9A-F]+$/.test(hex) ? hex : null;
};