| 660 | } |
| 661 | |
| 662 | function 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 | |
| 687 | export async function ipLookup( |
| 688 | request: FastifyRequest<{ Querystring: { ip?: string } }>, |