MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / isPrivateIP

Function isPrivateIP

apps/api/src/controllers/tools.controller.ts:662–685  ·  view source on GitHub ↗
(ip: string)

Source from the content-addressed store, hash-verified

660}
661
662function isPrivateIP(ip: string): boolean {
663 if (ip === '::1') return true;
664 if (ip.startsWith('::ffff:127.')) return true;
665 if (ip.startsWith('127.')) return true;
666 if (ip.startsWith('10.')) return true;
667 if (ip.startsWith('192.168.')) return true;
668 if (ip.startsWith('172.')) {
669 const parts = ip.split('.');
670 if (parts.length >= 2) {
671 const secondOctet = Number.parseInt(parts[1] || '0', 10);
672 if (secondOctet >= 16 && secondOctet <= 31) {
673 return true;
674 }
675 }
676 }
677 if (
678 ip.startsWith('fc00:') ||
679 ip.startsWith('fd00:') ||
680 ip.startsWith('fe80:')
681 ) {
682 return true;
683 }
684 return false;
685}
686
687export async function ipLookup(
688 request: FastifyRequest<{ Querystring: { ip?: string } }>,

Callers 1

ipLookupFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected