Ensure that the host weave bridge is exposed using the given CIDR address,
 and only the given CIDR address

 @param [String] cidr '10.81.0.X/16'
16705
def ensure_exposed(cidr)
      # configure new address
      # these will be added alongside any existing addresses
      if @executor_pool.expose(cidr)
        info "Exposed host node at cidr=#{cidr}"
      else
        error "Failed to expose host node at cidr=#{cidr}"
      end

      # cleanup any old addresses
      @executor_pool.ps('weave:expose') do |name, mac, *cidrs|
        cidrs.each do |exposed_cidr|
          if exposed_cidr != cidr
            warn "Migrating host node from cidr=#{exposed_cidr}"
            @executor_pool.hide(exposed_cidr)
          end
        end
      end
    end
586462
def ip_host(value, options=None, version=None):
    '''
    
    '''
    ipaddr_filter_out = _filter_ipaddr(value, options=options, version=version)
    if not ipaddr_filter_out:
        return
    if not isinstance(value, (list, tuple, types.GeneratorType)):
        return six.text_type(ipaddress.ip_interface(ipaddr_filter_out[0]))
    return [six.text_type(ipaddress.ip_interface(ip_a)) for ip_a in ipaddr_filter_out]
85673
def _unapply_xheaders(self) -> None:
        
        self.remote_ip = self._orig_remote_ip
        self.protocol = self._orig_protocol
1138070
def via(*proxy)
      proxy_hash = {}
      proxy_hash[:proxy_address]  = proxy[0] if proxy[0].is_a?(String)
      proxy_hash[:proxy_port]     = proxy[1] if proxy[1].is_a?(Integer)
      proxy_hash[:proxy_username] = proxy[2] if proxy[2].is_a?(String)
      proxy_hash[:proxy_password] = proxy[3] if proxy[3].is_a?(String)
      proxy_hash[:proxy_headers]  = proxy[2] if proxy[2].is_a?(Hash)
      proxy_hash[:proxy_headers]  = proxy[4] if proxy[4].is_a?(Hash)

      raise(RequestError, "invalid HTTP proxy: #{proxy_hash}") unless (2..5).cover?(proxy_hash.keys.size)

      branch default_options.with_proxy(proxy_hash)
    end
624199
def add_static_ip(n_ip=0)
      begin
        # required metadata values
        ipaddr = ENV["RS_IP#{n_ip}_ADDR"]
        netmask = ENV["RS_IP#{n_ip}_NETMASK"]
        # optional
        gateway = ENV["RS_IP#{n_ip}_GATEWAY"]
        device = shell_escape_if_necessary(device_name_from_mac(ENV["RS_IP#{n_ip}_MAC"]))

        if ipaddr
          # configure network adaptor
          attached_nameservers = nameservers_for_device(n_ip)

          logger.info "Setting up static IP address '#{ipaddr}' for '#{device}'"
          logger.debug "Netmask: '#{netmask}' ; Gateway: '#{gateway}'"
          logger.debug "Nameservers: '#{attached_nameservers.join(' ')}'" if attached_nameservers
          raise "FATAL: RS_IP#{n_ip}_NETMASK not defined ; Cannot configure static IP address" unless netmask

          ip = configure_network_adaptor(device, ipaddr, netmask, gateway, attached_nameservers)
        end
      rescue Exception => e
        logger.error "Detected an error while configuring static IP#{n_ip}: #{e.message}"
        raise e
      end
    end
966550
def listen(address, port) # :nodoc:
      listeners = Utils::create_listeners(address, port, @logger)
      if @config[:SSLEnable]
        unless ssl_context
          @ssl_context = setup_ssl_context(@config)
          @logger.info("\n" + @config[:SSLCertificate].to_text)
        end
        listeners.collect!{|svr|
          ssvr = ::OpenSSL::SSL::SSLServer.new(svr, ssl_context)
          ssvr.start_immediately = @config[:SSLStartImmediately]
          ssvr
        }
      end
      @listeners += listeners
    end
115654
private boolean inHostsList(DatanodeID node, String ipAddr) {
    Set<String> hostsList = hostsReader.getHosts();
    try {
      if (hostsList.isEmpty()
          || (ipAddr != null && hostsList.contains(ipAddr))
          || hostsList.contains(node.getHost())
          || hostsList.contains(node.getName())
          || ((node instanceof DatanodeInfo) && (hostsList.contains(((DatanodeInfo) node)
              .getHostName()) 
          || hostsList.contains(((DatanodeInfo) node).getHostName() + ":"
              + node.getPort()))) 
          // this is for the mixed mode in which the hostnames in the includes file
          // are followed with a "." and the datanodes are using IP addresses
          // during registration
          || (ipAddr != null && 
              hostsList.contains(InetAddress.getByName(ipAddr).getHostName() 
              + "."))) {
        return true;
      }
      
      // for several calls we pass ipAddr = null, but the datanode name
      // is an IP address, for this we need to do best effort reverse DNS 
      // resolution
      String host = getHostNameForIp(node.getHost());
      if (host != null) {
        return hostsList.contains(host + ".") || hostsList.contains(host);
      }
      
      // host is not in the list
      return false;
    } catch (UnknownHostException e) {
      LOG.error(e);
    }
    return false;
  }
1343526
public void setHttpsProxy(String host) {
    setProxyValue(HTTPS_SERVER, host);
    setProxyValue(USE_HTTPS, host != null);
  }
913715
def my_address_string(self):
        
        addr = getattr(self, 'client_address', ('', None))[0]

        # If listed in proxy_ips, use the X-Forwarded-For header, if present.
        if addr in self.proxy_ips:
            return self.headers.getheader('x-forwarded-for', addr)
        return addr
259858
def set_tunnel(self, host, port=None, headers=None):
        
        self._tunnel_host = host
        self._tunnel_port = port
        if headers:
            self._tunnel_headers = headers
        else:
            self._tunnel_headers.clear()
84564
def setup_link(self, interface, cidr):
        
        # clear old ipaddr in interface
        cmd = ['ip', 'addr', 'flush', 'dev', interface]
        agent_utils.execute(cmd, root=True)
        ip = IPNetwork(cidr)
        cmd = ['ip', 'addr', 'add', cidr, 'broadcast',
               str(ip.broadcast), 'dev', interface]
        stdcode, stdout = agent_utils.execute(cmd, root=True)
        if stdcode == 0:
            cmd = ['ip', 'link', 'set', 'dev', interface, 'up']
            stdcode, stdout = agent_utils.execute(cmd, root=True)
            if stdcode == 0:
                return agent_utils.make_response(code=stdcode)
        # execute failed.
        message = stdout.pop(0)
        return agent_utils.make_response(code=stdcode, message=message)
204580
def parse_ip6(ip_output, scope)
      cidr_ip = parse_ip_output(ip_output, /inet6 .* scope #{scope}/, 1)
      return unless cidr_ip

      parts = cidr_ip.split('/')
      @network_conf["address6_#{scope}".to_sym] = parts[0]
      @network_conf["prefix6_#{scope}".to_sym] = parts[1].to_i
    end
468464
def hosts2map (hosts):
    
    hostset = set()
    nets = []
    for host in hosts:
        if _host_cidrmask_re.match(host):
            host, mask = host.split("/")
            mask = int(mask)
            if not is_valid_cidrmask(mask):
                log.error(LOG_CHECK,
                          "CIDR mask %d is not a valid network mask", mask)
                continue
            if not is_valid_ipv4(host):
                log.error(LOG_CHECK, "host %r is not a valid ip address", host)
                continue
            nets.append(dq2net(host, cidr2mask(mask)))
        elif _host_netmask_re.match(host):
            host, mask = host.split("/")
            if not is_valid_ipv4(host):
                log.error(LOG_CHECK, "host %r is not a valid ip address", host)
                continue
            if not is_valid_ipv4(mask):
                log.error(LOG_CHECK,
                          "mask %r is not a valid ip network mask", mask)
                continue
            nets.append(dq2net(host, netmask2mask(mask)))
        elif is_valid_ip(host):
            hostset.add(expand_ip(host)[0])
        else:
            hostset |= set(resolve_host(host))
    return (hostset, nets)
786351
def cidr_netmask(cidr):
    '''
    
    '''
    ips = netaddr.IPNetwork(cidr)
    return six.text_type(ips.netmask)
1107934
def build_http(host, port)
      params = [host, port]
      params += @proxy_options.values_at(:host, :port, :user, :pass) unless @proxy_options.empty?
      add_ssl(Net::HTTP.new(*params))
    end
146390
public static function CIDRCheck($IP, $CIDR) {
      list ($net, $mask) = explode("/", $CIDR);

      // Allow non-standard /0 syntax
      if ($mask == 0) {
         if (ip2long($IP) == ip2long($net))
            return true;
         else
            return false;
      }

      $ip_net = ip2long($net);
      $ip_mask = ~((1 << (32 - $mask)) - 1);

      $ip_ip = ip2long($IP);

      $ip_ip_net = $ip_ip & $ip_mask;

      return ($ip_ip_net == $ip_net);
   }
524042
def natural_ipv4_netmask(ip, fmt='prefixlen'):
    '''
    
    '''
    bits = _ipv4_to_bits(ip)

    if bits.startswith('11'):
        mask = '24'
    elif bits.startswith('1'):
        mask = '16'
    else:
        mask = '8'

    if fmt == 'netmask':
        return cidr_to_ipv4_netmask(mask)
    else:
        return '/' + mask