MCPcopy
hub / github.com/MetaCubeX/metacubexd / isResolvableIP

Function isResolvableIP

packages/ui/composables/useReverseDns.ts:43–63  ·  view source on GitHub ↗
(ip: string | undefined)

Source from the content-addressed store, hash-verified

41// unspecified and link-local addresses (no useful reverse record); everything
42// else — private LAN or public, IPv4 or IPv6 — is allowed.
43export function isResolvableIP(ip: string | undefined): boolean {
44 if (!ip) return false
45
46 if (ip.includes(':')) {
47 const lower = ip.split('%')[0]!.toLowerCase()
48 if (lower === '::' || lower === '::1') return false
49 if (/^fe[89ab]/.test(lower)) return false // fe80::/10 link-local
50 return true
51 }
52
53 const parts = ip.split('.')
54 if (parts.length !== 4) return false
55 for (const part of parts) {
56 if (!/^\d{1,3}$/.test(part) || Number(part) > 255) return false
57 }
58 const a = Number(parts[0])
59 const b = Number(parts[1])
60 if (a === 127 || a === 0) return false // loopback / unspecified
61 if (a === 169 && b === 254) return false // 169.254.0.0/16 link-local
62 return true
63}
64
65// 192.168.50.62 -> 62.50.168.192.in-addr.arpa
66function reverseNameV4(ip: string): string | null {

Callers 2

lookupFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected