sample_data_utils/net.py
def ip(private=True, public=True, max_attempts=10000):
    """
        returns a :class:`netaddr.IPAddress` instance with a random value

    :param private: if False does not return private networks
    :param public:  if False does not return public networks
    :param max_attempts:
    """
    if not (private or public):
        raise ValueError('Cannot disable both `private` and `public` network')

    if private != public:
        if private:
            is_valid = lambda address: address.is_private()
            not_valid = [n for n in range(1, 255) if n not in NOT_NET]
        else:
            is_valid = lambda address: not address.is_private()
            not_valid = NOT_NET

        attempt = 0
        while attempt < max_attempts:
            attempt += 1
            ip = IPAddress(ipaddress(not_valid))
            if is_valid(ip):
                return ip
    else:
        return IPAddress(ipaddress())
def ip(private=True, public=True, max_attempts=10000):
    """
        returns a :class:`netaddr.IPAddress` instance with a random value

    :param private: if False does not return private networks
    :param public:  if False does not return public networks
    :param max_attempts:
    """
    if not (private or public):
        raise ValueError('Cannot disable both `private` and `public` network')

    if private != public:
        if private:
            is_valid = lambda address: address.is_private()
            not_valid = [n for n in range(1, 255) if n not in NOT_NET]
        else:
            is_valid = lambda address: not address.is_private()
            not_valid = NOT_NET

        attempt = 0
        while attempt < max_attempts:
            attempt += 1
            ip = IPAddress(ipaddress(not_valid))
            if is_valid(ip):
                return ip
    else:
        return IPAddress(ipaddress())
def ip ( private = True , public = True , max_attempts = 10000 ) : if not ( private or public ) : raise ValueError ( 'Cannot disable both `private` and `public` network' ) if private != public : if private : is_valid = lambda address : address . is_private ( ) not_valid = [ n for n in range ( 1 , 255 ) if n not in NOT_NET ] else : is_valid = lambda address : not address . is_private ( ) not_valid = NOT_NET attempt = 0 while attempt < max_attempts : attempt += 1 ip = IPAddress ( ipaddress ( not_valid ) ) if is_valid ( ip ) : return ip else : return IPAddress ( ipaddress ( ) )
returns a :class:`netaddr.IPAddress` instance with a random value

    :param private: if False does not return private networks
    :param public:  if False does not return public networks
    :param max_attempts:
returns a : class : netaddr . IPAddress instance with a random value