

def gen_ipaddr(ip3=False, ipv6=False, prefix=()):
    'Generates a random IP address.\n\n    You can also specify an IP address prefix if you are interested in\n    local network address generation, etc.\n\n    :param bool ip3: Whether to generate a 3 or 4 group IP.\n    :param bool ipv6: Whether to generate IPv6 or IPv4\n    :param list prefix: A prefix to be used for an IP (e.g. [10, 0, 1]). It\n        must be an iterable with strings or integers. Can be left unspecified or\n        empty.\n    :returns: An IP address.\n    :rtype: str\n    :raises: ``ValueError`` if ``prefix`` would lead to no random fields at all.\n        This means the length that triggers the ``ValueError`` is 4 for regular\n        IPv4, 3 for IPv4 with ip3 and 8 for IPv6. It will be raised in any case\n        the prefix length reaches or exceeds those values.\n\n    '
    if ipv6:
        rng = 8
    elif ip3:
        rng = 3
    else:
        rng = 4
    prefix = [str(field) for field in prefix]
    rng -= len(prefix)
    if (rng == 0):
        raise ValueError('Prefix {} would lead to no randomness at all'.format(repr(prefix)))
    elif (rng < 0):
        raise ValueError('Prefix {} is too long for this configuration'.format(repr(prefix)))
    random.seed()
    if ipv6:
        random_fields = ['{0:x}'.format(random.randint(0, ((2 ** 16) - 1))) for _ in range(rng)]
        ipaddr = ':'.join((prefix + random_fields))
    else:
        random_fields = [str(random.randrange(0, 255, 1)) for _ in range(rng)]
        ipaddr = '.'.join((prefix + random_fields))
        if ip3:
            ipaddr = (ipaddr + '.0')
    return _make_unicode(ipaddr)

dataset/ETHPy150Open omaciel/fauxfactory/fauxfactory/__init__.py gen_ipaddr/original