mirror of
https://github.com/jason5ng32/MyIP.git
synced 2026-11-04 08:55:47 +00:00
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>
23 lines
890 B
JavaScript
23 lines
890 B
JavaScript
// 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;
|
||
};
|