AW: ipv6 PTR in zone file

Shumon Huque shuque at upenn.edu
Fri Apr 15 18:53:30 UTC 2011


On Fri, Apr 15, 2011 at 10:56:00AM -0400, John Wobus wrote:
> >pint> use Net::IP
> >pint> $foo = new Net::IP '2001:db8::42'
> >3
> >pint> $foo->reverse_ip()
> >2.4.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.ip6.arpa.
> >pint>
> 
> Or you could just dash off the simple perl expression to do the job:
> 
> my $ptr = do {
>     my($head,$tail) =
>       map { join '', map { sprintf '%04s',$_; } split /:/,$_; }
>       split /::/, $addr  . '::', 3;
>     my $hex32 = '0' x 32;
>     substr( $hex32, 0, length($head) ) = $head;
>     substr( $hex32, 32, -length($tail) ) =  $tail;
>     join '.', ( reverse split //, $hex32 ), 'ip6.arpa';
>     };
> 

In case Pythonistas feel neglected, here's my contribution:

--------------------- Cut here ------------------

#!/usr/bin/env python
#

import sys, socket

def ip6toptr(address):
    """return PTR owner name of an IPv6 address"""
    try:
        packed = socket.inet_pton(socket.AF_INET6, address)
    except socket.error:
        raise ValueError("%s isn't an IPv6 address" % address)   
    hexstring = ''.join(["%02x" % ord(x) for x in packed])
    ptrowner = "%s.ip6.arpa" % \
               '.'.join([x for x in hexstring[::-1]])
    return ptrowner

if __name__ == '__main__':
    print ip6toptr(sys.argv[1])

--------------------- Cut here ------------------

-- 
Shumon Huque
University of Pennsylvania.



More information about the bind-users mailing list