// GetIPs returns a slice of IP addresses assigned to the VM. The PublicIP or
// PrivateIP consts can be used to retrieve respective IP address type. It
// returns nil if there was an error obtaining the IPs.
167058
func (vm *VM) GetIPs() ([]net.IP, error) {
	server, err := getServer(vm)
	if server == nil || err != nil {
		// Probably need to call Provision first.
		return nil, err
	}

	client, err := getNetworkClient(vm)
	if client == nil || err != nil {
		// Probably need to create some network first.
		return nil, err
	}
	ips := make([]net.IP, 2)
	for _, networkID := range vm.Networks {
		network, err := networks.Get(client, networkID).Extract()
		if err != nil {
			return nil, err
		}

		addressSlice := server.Addresses[network.Name].([]interface{})
		for _, addressElement := range addressSlice {
			addressBlock := addressElement.(map[string]interface{})
			ipType := addressBlock["OS-EXT-IPS:type"].(string)
			ip := addressBlock["addr"].(string)
			if ipType == "floating" {
				ips[PublicIP] = net.ParseIP(ip)
			}
			if ipType == "fixed" {
				ips[PrivateIP] = net.ParseIP(ip)
			}
		}
	}

	return ips, nil
}
789090
func getIp(r *http.Request) string {
	for _, h := range []string{"X-Forwarded-For", "X-Real-Ip"} {
		for _, ip := range strings.Split(r.Header.Get(h), ",") {
			if len(ip) == 0 {
				continue
			}
			realIP := net.ParseIP(strings.Replace(ip, " ", "", -1))
			return realIP.String()
		}
	}

	// not found in header
	host, _, err := net.SplitHostPort(r.RemoteAddr)
	if err != nil {
		// just return remote addr
		return r.RemoteAddr
	}

	return host
}
26216
func (r Network_Gateway) GetPrivateIpAddress() (resp datatypes.Network_Subnet_IpAddress, err error) {
	err = r.Session.DoRequest("SoftLayer_Network_Gateway", "getPrivateIpAddress", nil, &r.Options, &resp)
	return
}
784377
func GetIP(conn client.Connection, req IPRequest) (*IP, error) {
	logger := plog.WithFields(log.Fields{
		"hostid":    req.HostID,
		"ipaddress": req.IPAddress,
	})

	basepth := "/"
	if req.PoolID != "" {
		basepth = path.Join("/pools", req.PoolID)
	}

	// Get the current pool ip
	ppth := path.Join(basepth, "/ips", req.IPID())
	pdat := &PoolIP{}
	if err := conn.Get(ppth, pdat); err != nil {
		logger.WithError(err).Debug("Could not look up virtual ip on resource pool")
		// TODO: error
		return nil, err
	}
	logger.Debug("Found pool ip")

	// Get the current host ip
	hpth := path.Join(basepth, "/hosts", req.HostID, "ips", req.IPID())
	hdat := &HostIP{}
	if err := conn.Get(hpth, hdat); err != nil {
		logger.WithError(err).Debug("Could not look up virtual ip on host")
		// TODO: error
		return nil, err
	}
	logger.Debug("Found host ip")

	return &IP{
		PoolIP:    *pdat,
		HostIP:    *hdat,
		HostID:    req.HostID,
		IPAddress: req.IPAddress,
	}, nil
}
189685
func GetIP(r *http.Request, options ...Options) net.IP {
	if len(options) >= 1 && options[0].TrustForwardHeader {
		ip := r.Header.Get("X-Forwarded-For")
		if ip != "" {
			parts := strings.SplitN(ip, ",", 2)
			part := strings.TrimSpace(parts[0])
			return net.ParseIP(part)
		}

		ip = strings.TrimSpace(r.Header.Get("X-Real-IP"))
		if ip != "" {
			return net.ParseIP(ip)
		}
	}

	remoteAddr := strings.TrimSpace(r.RemoteAddr)
	host, _, err := net.SplitHostPort(remoteAddr)
	if err != nil {
		return net.ParseIP(remoteAddr)
	}

	return net.ParseIP(host)
}
1024647
func IPs() []string {
	ifaces, err := net.Interfaces()
	if err != nil {
		return nil
	}

	var ipAddrs []string

	for _, i := range ifaces {
		addrs, err := i.Addrs()
		if err != nil {
			continue
		}

		for _, addr := range addrs {
			var ip net.IP
			switch v := addr.(type) {
			case *net.IPNet:
				ip = v.IP
			case *net.IPAddr:
				ip = v.IP
			}

			if ip == nil {
				continue
			}

			ip = ip.To4()
			if ip == nil {
				continue
			}

			ipAddrs = append(ipAddrs, ip.String())
		}
	}

	return ipAddrs
}
1196416
func (s *CheckerStrategy) GetIP(req *http.Request) string {
	if s.Checker == nil {
		return ""
	}

	xff := req.Header.Get(xForwardedFor)
	xffs := strings.Split(xff, ",")

	for i := len(xffs) - 1; i >= 0; i-- {
		xffTrimmed := strings.TrimSpace(xffs[i])
		if contain, _ := s.Checker.Contains(xffTrimmed); !contain {
			return xffTrimmed
		}
	}
	return ""
}
1040441
func (d *Driver) GetIP() (string, error) {
	ip, err := net.ChooseBindAddress(nil)
	if err != nil {
		return "", err
	}
	return ip.String(), nil
}
932665
func (c *Client) GetPoolIPs(poolID string) (*pool.PoolIPs, error) {
	var poolIPs pool.PoolIPs
	if err := c.call("GetPoolIPs", poolID, &poolIPs); err != nil {
		return nil, err
	}
	return &poolIPs, nil
}
161170
func GetIP(daemonHost string) string {
	u, err := url.Parse(daemonHost)
	if err != nil {
		log.Errorf("[GetIP] GetIP %s failed %v", daemonHost, err)
		return ""
	}
	return u.Hostname()
}
805083
func (p *propZone) GetVPCProxyIPAddress() string {
	if p.Zone == nil {
		return ""
	}
	return p.Zone.GetVPCProxyIPAddress()
}
851906
func (vm *VM) getPublicIP(authorizer autorest.Authorizer) (net.IP, error) {
	publicIPAddressesClient := network.NewPublicIPAddressesClient(vm.Creds.SubscriptionID)
	publicIPAddressesClient.Authorizer = authorizer

	resPublicIP, err := publicIPAddressesClient.Get(vm.ResourceGroup, vm.PublicIP, "")
	if err != nil {
		return nil, err
	}

	if resPublicIP.PublicIPAddressPropertiesFormat == nil || resPublicIP.PublicIPAddressPropertiesFormat.IPAddress == nil ||
		*resPublicIP.PublicIPAddressPropertiesFormat.IPAddress == "" {
		return nil, fmt.Errorf("VM has no public IP address")
	}
	return net.ParseIP(*resPublicIP.PublicIPAddressPropertiesFormat.IPAddress), nil
}
966226
func (mg *MailgunImpl) GetIP(ctx context.Context, ip string) (IPAddress, error) {
	r := newHTTPRequest(generatePublicApiUrl(mg, ipsEndpoint) + "/" + ip)
	r.setClient(mg.Client())
	r.setBasicAuth(basicAuthUser, mg.APIKey())
	var resp IPAddress
	err := getResponseFromJSON(ctx, r, &resp)
	return resp, err
}
723389
func getIP(showAddress string) string {
	list := strings.SplitN(showAddress, ":", 2)
	if len(list) != 2 {
		return ""
	}
	return strings.TrimSpace(list[1])
}
931370
func (m *Cluster) GetHosts() []*core.Address {
	if m != nil {
		return m.Hosts
	}
	return nil
}
621968
func (api *ProjectsAPI) GetVMs(projectID string, options *VmGetOptions) (result *VMs, err error) {
	uri := api.client.Endpoint + projectUrl + projectID + "/vms"
	if options != nil {
		uri += getQueryString(options)
	}
	res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
	if err != nil {
		return
	}

	result = &VMs{}
	err = json.Unmarshal(res, result)
	return
}
516611
func (s *DescribeElasticIpsInput) SetIps(v []*string) *DescribeElasticIpsInput {
	s.Ips = v
	return s
}