(ip, version)
return ret
Transform an integer string into an IP address.
Transform an integer string into an IP address.
Transform an integer string into an IP address .
def intToIp(ip, version):
    """Transform an integer string into an IP address."""

    # just to be sure and hoping for Python 2.22
    ip = long(ip)

    if ip < 0:
        raise ValueError("IPs can't be negative: %d" % (ip))

    ret = ''
    if version == 4:
        if ip > 0xffffffff:
            raise ValueError(
                "IPv4 Addresses can't be larger than 0xffffffff: %s" %
                (hex(ip)))
        for l in range(4):
            ret = str(ip & 0xff) + '.' + ret
            ip = ip >> 8
        ret = ret[:-1]
    elif version == 6:
        if ip > 0xffffffffffffffffffffffffffffffff:
            raise ValueError(
                "IPv6 Addresses can't be larger than 0xffffffffffffffffffffffffffffffff: %s" %
                (hex(ip)))
        l = '0' * 32 + hex(ip)[2:-1]
        for x in range(1, 33):
            ret = l[-x] + ret
            if x % 4 == 0:
                ret = ':' + ret
        ret = ret[1:]
    else:
        raise ValueError("only IPv4 and IPv6 supported")

    return ret
def intToIp ( ip , version ) : # just to be sure and hoping for Python 2.22 ip = long ( ip ) if ip < 0 : raise ValueError ( "IPs can't be negative: %d" % ( ip ) ) ret = '' if version == 4 : if ip > 0xffffffff : raise ValueError ( "IPv4 Addresses can't be larger than 0xffffffff: %s" % ( hex ( ip ) ) ) for l in range ( 4 ) : ret = str ( ip & 0xff ) + '.' + ret ip = ip >> 8 ret = ret [ : - 1 ] elif version == 6 : if ip > 0xffffffffffffffffffffffffffffffff : raise ValueError ( "IPv6 Addresses can't be larger than 0xffffffffffffffffffffffffffffffff: %s" % ( hex ( ip ) ) ) l = '0' * 32 + hex ( ip ) [ 2 : - 1 ] for x in range ( 1 , 33 ) : ret = l [ - x ] + ret if x % 4 == 0 : ret = ':' + ret ret = ret [ 1 : ] else : raise ValueError ( "only IPv4 and IPv6 supported" ) return ret