Generate a random IPv4 address.

        :param with_port: Add port to IP.
        :return: Random IPv4 address.

        :Example:
            19.121.223.58
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
1138183
def create_dhcprelay_ipv4(self):
        """"""
        return DHCPRelayIPv4(
            self.networkapi_url,
            self.user,
            self.password,
            self.user_ldap)
1345773
def pick_port(self):
        """"""
        ports = set(range(self.min_port, self.min_port + self.port_range))
        return port_for.select_random(ports)
753032
def create(host, port):
    
    wrapper = WrapperServer({
        'server': None
    })
    d = {
        'listen_port': port,
        'changer': wrapper
    }
    if host:
        d['listen_bind_ip'] = host

    ses = MeasureServer(d)
    wrapper.server = ses
    return [wrapper], cmd_line
1136507
def port(self, port_range: PortRange = PortRange.ALL) -> int:
        
        if port_range and port_range in PortRange:
            return self.random.randint(*port_range.value)
        else:
            raise NonEnumerableError(PortRange)
550288
def create(self, networkipv4s):
        

        data = {'networks': networkipv4s}
        return super(ApiNetworkIPv4, self).post('api/v3/networkv4/', data)
717815
def to_address(self, port: str):
        
        # check to see if user passed in a string
        # if they did, they want to use that instead
        if isinstance(port, str) and len(port) > 6:
            return port

        zmq_address = '{}://{}:{}'
        return zmq_address.format(self.protocol,
                                  self.address,
                                  port)
769521
def get_ipv4(hostname):
    
    addrinfo = socket.getaddrinfo(hostname, None, socket.AF_INET,
                                  socket.SOCK_STREAM)
    return [addrinfo[x][4][0] for x in range(len(addrinfo))]
552738
def _choose_port(self):
        
        # instead of random let's base it on the name chosen (and the site name)
        return 5000 + unpack('Q',
                             sha((self.name + self.site_name)
                             .decode('ascii')).digest()[:8])[0] % 1000
237736
def ip4_address(self):
        
        if self._ip4_address is None and self.network is not None:
            self._ip4_address = self._get_ip_address(
                libvirt.VIR_IP_ADDR_TYPE_IPV4)

        return self._ip4_address
393459
def add_ipv6addr(self, ipv6addr):
        
        for addr in self.ipv6addrs:
            if ((isinstance(addr, dict) and addr['ipv6addr'] == ipv6addr) or
                (isinstance(addr, HostIPv4) and addr.ipv6addr == ipv6addr)):
                raise ValueError('Already exists')
        self.ipv6addrs.append({'ipv6addr': ipv6addr})
1327184
def iprange(self, *args):
        
        call_args = list(args)
        return self.random.choice(IPRange(call_args.pop(0), call_args.pop(0)))
281110
def hostname_with_port(self):
        ''''''
        default_port = RELATIVE_SCHEME_DEFAULT_PORTS.get(self.scheme)
        if not default_port:
            return ''

        assert '[' not in self.hostname
        assert ']' not in self.hostname

        if self.is_ipv6():
            hostname = '[{}]'.format(self.hostname)
        else:
            hostname = self.hostname

        if default_port != self.port:
            return '{}:{}'.format(hostname, self.port)
        else:
            return hostname
40291
def set_address(network, address):
    
    if network.find('.//ip') is not None:
        raise RuntimeError("Address already specified in XML configuration.")

    netmask = str(address.netmask)
    ipv4 = str(address[1])
    dhcp_start = str(address[2])
    dhcp_end = str(address[-2])
    ip = etree.SubElement(network, 'ip', address=ipv4, netmask=netmask)
    dhcp = etree.SubElement(ip, 'dhcp')

    etree.SubElement(dhcp, 'range', start=dhcp_start, end=dhcp_end)
826317
public static Address from(int port) {
    try {
      InetAddress address = getLocalAddress();
      return new Address(address.getHostName(), port);
    } catch (UnknownHostException e) {
      throw new IllegalArgumentException("Failed to locate host", e);
    }
  }
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
915128
def create_api_network_ipv4(self):
        """"""

        return ApiNetworkIPv4(
            self.networkapi_url,
            self.user,
            self.password,
            self.user_ldap)