20-07-2020, Saat: 21:47
Merhaba,
Anlatım: Taha Koçak (T1xLnN) Aittir.
PHP Kod:
[code]
function ipv4_to_ipv6(string $ip): string
{
if ($ip === '0.0.0.0/0') {
return '::';
}
list($address, $mask) = explode('/', $ip, 2) + [null, null];
if (!(bool)filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) || (isset($mask) && !ctype_digit($mask))) {
throw new \InvalidArgumentException("'$ip' is not a valid IPv4 address or cidr");
}
$bytes = array_map('dechex', explode('.', $address));
return vsprintf('0:0:0:0:0:ffff:%02s%02s:%02s%02s', $bytes) . (isset($mask) ? '/' . ($mask + 96) : '');
}
[/code]