SimplePie_Net_IPv6::SplitV64 PHP 메소드

SplitV64() 공개 메소드

RFC 2373 allows you to note the last two parts of an IPv6 address as an IPv4 compatible address Example: 0:0:0:0:0:0:13.1.68.3 0:0:0:0:0:FFFF:129.144.52.38
public SplitV64 ( string $ip ) : array
$ip string a valid IPv6-address (hex format)
리턴 array [0] contains the IPv6 part, [1] the IPv4 part (hex format)
    function SplitV64($ip)
    {
        $ip = SimplePie_Net_IPv6::Uncompress($ip);
        if (strstr($ip, '.')) {
            $pos = strrpos($ip, ':');
            $ip[$pos] = '_';
            $ipPart = explode('_', $ip);
            return $ipPart;
        } else {
            return array($ip, '');
        }
    }

Usage Example

예제 #1
0
 public static function checkIPv6($ip)
 {
     $ipPart = SimplePie_Net_IPv6::SplitV64($ip);
     $count = 0;
     if (!empty($ipPart[0])) {
         $ipv6 = explode(':', $ipPart[0]);
         for ($i = 0; $i < count($ipv6); $i++) {
             $dec = hexdec($ipv6[$i]);
             $hex = strtoupper(preg_replace('/^[0]{1,3}(.*[0-9a-fA-F])$/', '\\1', $ipv6[$i]));
             if ($ipv6[$i] >= 0 && $dec <= 65535 && $hex === strtoupper(dechex($dec))) {
                 $count++;
             }
         }
         if ($count === 8) {
             return true;
         } elseif ($count === 6 && !empty($ipPart[1])) {
             $ipv4 = explode('.', $ipPart[1]);
             $count = 0;
             foreach ($ipv4 as $ipv4_part) {
                 if ($ipv4_part >= 0 && $ipv4_part <= 255 && preg_match('/^\\d{1,3}$/', $ipv4_part)) {
                     $count++;
                 }
             }
             if ($count === 4) {
                 return true;
             }
         } else {
             return false;
         }
     } else {
         return false;
     }
 }