Produce a random IPv4 address or network with a valid CIDR.

        :param network: Network address
        :param address_class: IPv4 address class (a, b, or c)
        :param private: Public or private
        :returns: IPv4
331272
def ipv4(self, network=False, address_class=None, private=None):
        
        if private is True:
            return self.ipv4_private(address_class=address_class,
                                     network=network)
        elif private is False:
            return self.ipv4_public(address_class=address_class,
                                    network=network)

        # if neither private nor public is required explicitly,
        # generate from whole requested address space
        if address_class:
            all_networks = [_IPv4Constants._network_classes[address_class]]
        else:
            # if no address class is choosen, use whole IPv4 pool
            all_networks = [ip_network('0.0.0.0/0')]

        # exclude special networks
        all_networks = self._exclude_ipv4_networks(
            all_networks,
            _IPv4Constants._excluded_networks,
        )

        # choose random network from the list
        random_network = self.generator.random.choice(all_networks)

        return self._random_ipv4_address_from_subnet(random_network, network)
969683
def _get_ips(networks):
    '''
    
    '''
    v4s = networks.get('v4')
    v6s = networks.get('v6')
    public_ips = []
    private_ips = []

    if v4s:
        for item in v4s:
            ip_type = item.get('type')
            ip_address = item.get('ip_address')
            if ip_type == 'public':
                public_ips.append(ip_address)
            if ip_type == 'private':
                private_ips.append(ip_address)

    if v6s:
        for item in v6s:
            ip_type = item.get('type')
            ip_address = item.get('ip_address')
            if ip_type == 'public':
                public_ips.append(ip_address)
            if ip_type == 'private':
                private_ips.append(ip_address)

    return public_ips, private_ips
1120327
def generate_address(hypervisor, configuration):
    """"""
    ipv4 = configuration['ipv4']
    prefix = configuration['prefix']
    subnet_prefix = configuration['subnet_prefix']
    subnet_address = ipaddress.IPv4Network(u'/'.join((str(ipv4), str(prefix))))
    net_address_pool = subnet_address.subnets(new_prefix=subnet_prefix)

    return address_lookup(hypervisor, net_address_pool)
1217852
def create_subnet(self, network, cidr, name=None, ip_version=4):
        '''
        
        '''
        net_id = self._find_network_id(network)
        body = {'cidr': cidr,
                'ip_version': ip_version,
                'network_id': net_id,
                'name': name}
        return self.network_conn.create_subnet(body={'subnet': body})
1299158
def network_protocol(self, layer: Optional[Layer] = None) -> str:
        
        key = self._validate_enum(item=layer, enum=Layer)
        protocols = NETWORK_PROTOCOLS[key]
        return self.random.choice(protocols)
442674
def AsIPAddr(self):
    """"""
    if self.packed_bytes is None:
      return None

    packed_bytes = self.packed_bytes.AsBytes()

    if self.address_type == NetworkAddress.Family.INET:
      return ipaddress.IPv4Address(packed_bytes)
    if self.address_type == NetworkAddress.Family.INET6:
      return ipaddress.IPv6Address(packed_bytes)

    message = "IP address has invalid type: {}".format(self.address_type)
    raise ValueError(message)
344229
def create_api_v4_ipv4(self):
        """"""

        return ApiV4IPv4(
            self.networkapi_url,
            self.user,
            self.password,
            self.user_ldap)
756078
def ip_address(self,
                   container: Container
                   ) -> Union[IPv4Address, IPv6Address]:
        
        r = self.__api.get('containers/{}/ip'.format(container.uid))
        if r.status_code == 200:
            return r.json()
        self.__api.handle_erroneous_response(r)
41317
def ip_v4_network_validator(v: Any) -> IPv4Network:
    
    if isinstance(v, IPv4Network):
        return v

    with change_exception(errors.IPv4NetworkError, ValueError):
        return IPv4Network(v)
688453
def network_create(request, **kwargs):
    
    LOG.debug("network_create(): kwargs = %s", kwargs)
    if 'tenant_id' not in kwargs:
        kwargs['tenant_id'] = request.user.project_id
    body = {'network': kwargs}
    network = neutronclient(request).create_network(body=body).get('network')
    return Network(network)
127761
def is_private(self):
        
        private_10 = IPv4Network(u'10.0.0.0/8')
        private_172 = IPv4Network(u'172.16.0.0/12')
        private_192 = IPv4Network(u'192.168.0.0/16')
        return (self in private_10 or
                self in private_172 or
                self in private_192)
993353
def cidr_to_ipv4_netmask(cidr_bits):
    '''
    
    '''
    try:
        cidr_bits = int(cidr_bits)
        if not 1 <= cidr_bits <= 32:
            return ''
    except ValueError:
        return ''

    netmask = ''
    for idx in range(4):
        if idx:
            netmask += '.'
        if cidr_bits >= 8:
            netmask += '255'
            cidr_bits -= 8
        else:
            netmask += '{0:d}'.format(256 - (2 ** (8 - cidr_bits)))
            cidr_bits = 0
    return netmask
423460
def ip_v4(self, with_port: bool = False) -> str:
        
        ip = '.'.join(str(self.random.randint(0, 255)) for _ in range(4))

        if with_port:
            ip += ':{}'.format(self.port())

        return ip
221287
function peerResolved (ip, addressType) {
    // Possible cancelation during DNS lookup.
    if (!socket._connecting) return;

    socket._peer = { address: ip || '127.0.0.1', port: options.port };

    // Generate random bytes used to set randomized socket properties.
    // `crypto.randomBytes` calls OpenSSL `RAND_bytes` to generate the bytes.
    //
    //  * [RAND_bytes](http://www.openssl.org/docs/crypto/RAND_bytes.html).
    //  * [node_crypto.cc](https://github.com/joyent/node/blob/v0.8/src/node_crypto.cc#L4517)
    crypto.randomBytes(4, valid(randomzied));
  }
1104670
def to_ipv6(net)
			if (!net.kind_of?(IPv6Net))
				raise ArgumentError, "Expected an IPv6Net object for 'net' but got a #{net.class}."
			end
			
			if (net.netmask.prefix_len != 64)
				return nil
			end
			
			# set u/l bit to 0
			hostId = @addr ^ 0x0200000000000000
			ipAddr = net.network.addr | hostId
			return IPv6.new(ipAddr)
		end
774894
def create_private_ip(linode_id):
    
    '''
    kwargs = {'LinodeID': linode_id}
    result = _query('linode', 'ip.addprivate', args=kwargs)

    return _clean_data(result)
973541
def random_ipv4(cidr='10.0.0.0/8'):
    
    try:
        u_cidr = unicode(cidr)
    except NameError:
        u_cidr = cidr
    network = ipaddress.ip_network(u_cidr)
    start = int(network.network_address) + 1
    end = int(network.broadcast_address)
    randint = random.randrange(start, end)
    return ipaddress.ip_address(randint)