MCPcopy Create free account
hub / github.com/simstudioai/sim / isPrivateIPv4

Function isPrivateIPv4

apps/sim/lib/api/contracts/tools/sap.ts:52–65  ·  view source on GitHub ↗
(host: string)

Source from the content-addressed store, hash-verified

50])
51
52function isPrivateIPv4(host: string): boolean {
53 const match = host.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)
54 if (!match) return false
55 const octets = match.slice(1, 5).map(Number) as [number, number, number, number]
56 if (octets.some((octet) => octet < 0 || octet > 255)) return false
57 const [a, b] = octets
58 if (a === 10) return true
59 if (a === 172 && b >= 16 && b <= 31) return true
60 if (a === 192 && b === 168) return true
61 if (a === 127) return true
62 if (a === 169 && b === 254) return true
63 if (a === 0) return true
64 return false
65}
66
67function extractIPv4MappedHost(host: string): string | null {
68 const stripped = host.startsWith('[') && host.endsWith(']') ? host.slice(1, -1) : host

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected