def ptr_to_addr(ptr):
    """Return IP address string from PTR hostname string.

    >>> ptr_to_addr('2.1.168.192.in-addr.arpa')
    '192.168.1.2'
    >>> ptr_to_addr('f.f.f.2.6.3.f.e.2.8.f.6.0.3.7.6.5.5.a.8.f.1.6.3.e.1.0.0'
    ...             '.1.0.0.2.ip6.arpa')
    '2001:001e:361f:8a55:6730:6f82:ef36:2fff'
    """
    if '.in-addr.arpa' in ptr:
        return '.'.join(reversed(ptr.split('.')[:4]))
    if '.ip6.arpa' in ptr:
        return ':'.join(['%s' * 4] * 8) % tuple(reversed(ptr.split('.')[:32]))