PHP: IPV6 reverse DNS entries

Reverse DNS (PTR) entries in IPV6 are different than their IPV4 counterparts. To create an IPV6 reverse entry, you have to: fully expand the address, reverse it, and add a period between each character.

For example: 2001:db8::60 reverses to 0.6.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.

I wrote a simple PHP function to handle this for me:

function ipv6_ptr($ip_str) {
    $hex = unpack("H*hex", inet_pton($ip_str));
    $str = strrev($hex['hex']);
    $p   = str_split($str);
    $ret = join(".",$p);

    return $ret;
}
Leave A Reply
All content licensed under the Creative Commons License