function is_known_ip($ip) { // updated: 2025-04-04 // Convert IP string to number if (is_string($ip)) { $bytes = explode('.', $ip); $ip = 0; foreach ($bytes as $n) { $ip <<= 8; $ip |= (int)$n; } } // Check rules switch ($ip & 0b0_11111111_11111111_11110000_00000000) { // mask: 255.255.240.0 case 0b0_11000001_00101011_11000000_00000000: // ip: 193.43.192.0 return true; } switch ($ip & 0b0_11111111_11111111_11111111_00000000) { // mask: 255.255.255.0 case 0b0_10111100_11010010_11101111_00000000: // ip: 188.210.239.0 return true; } switch ($ip & 0b0_11111111_11111111_11111111_11100000) { // mask: 255.255.255.224 case 0b0_01001110_00000110_01000011_10000000: // ip: 78.6.67.128 return true; } switch ($ip & 0b0_11111111_11111111_11111111_11111000) { // mask: 255.255.255.248 case 0b0_01001110_00000101_01001101_01100000: // ip: 78.5.77.96 return true; } switch ($ip & 0b0_11111111_11111111_11111111_11111111) { // mask: 255.255.255.255 case 0b0_11010100_01001101_01011111_00100011: // ip: 212.77.95.35 return true; } return false; }