// IP sets the parser to a net.IP parser.
762198
func (p *parserMixin) IP() (target *net.IP) {
	target = new(net.IP)
	p.IPVar(target)
	return
}
1063468
func (p *parserMixin) IPVar(target *net.IP) {
	p.SetValue(newIPValue(target))
}
19041
func AssignIP(dhcpHandler *DHCPHandler, ipRange string) (map[string]uint32, []net.IP) {
	couple := make(map[string]uint32)
	var iplist []net.IP
	if ipRange != "" {
		rgx, _ := regexp.Compile("((?:[0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}):((?:[0-9]{1,3}.){3}(?:[0-9]{1,3}))")
		ipRangeArray := strings.Split(ipRange, ",")
		if len(ipRangeArray) >= 1 {
			for _, rangeip := range ipRangeArray {
				result := rgx.FindStringSubmatch(rangeip)
				position := uint32(binary.BigEndian.Uint32(net.ParseIP(result[2]).To4())) - uint32(binary.BigEndian.Uint32(dhcpHandler.start.To4()))
				// Remove the position in the roaming bitmap
				dhcpHandler.available.ReserveIPIndex(uint64(position), result[1])
				couple[result[1]] = position
				iplist = append(iplist, net.ParseIP(result[2]))
			}
		}
	}
	return couple, iplist
}
1227588
func (req IPRequest) IPID() string {
	return fmt.Sprintf("%s-%s", req.HostID, req.IPAddress)
}
800727
func (r *Request) IP() string {
	if r.ip != "" {
		return r.ip
	}

	ip, _, err := net.SplitHostPort(r.W.RemoteAddr().String())
	if err != nil {
		r.ip = r.W.RemoteAddr().String()
		return r.ip
	}

	r.ip = ip
	return r.ip
}
921463
func (s *DedicatedIp) SetIp(v string) *DedicatedIp {
	s.Ip = &v
	return s
}
1902
func (internet Internet) IPv6(v reflect.Value) (interface{}, error) {
	return internet.ipv6(), nil
}
1253482
func supportedIP(ip net.IP) net.IP {
	if supportsIPv4 {
		if v4 := ip.To4(); v4 != nil {
			return v4
		}
	}
	if supportsIPv6 && len(ip) == net.IPv6len {
		return ip
	}
	return nil
}
1308645
func NewIP(nip net.IP) IP {
	var ip IP
	copy(ip[:], nip.To16())
	return ip
}
439847
func DefaultIP() string {
	addrs, err := netInterfaceAddrs()
	if err == nil {
		for _, addr := range addrs {
			if ip, ok := addr.(*net.IPNet); ok && !ip.IP.IsLoopback() {
				if ip.IP.To4() != nil {
					return ip.IP.String()
				}
			}
		}
	}

	return ""
}
301933
func (f ipAddressFunc) evaluate(values map[string][]string) bool {
	IPs := []net.IP{}
	requestValue, ok := values[http.CanonicalHeaderKey(f.k.Name())]
	if !ok {
		requestValue = values[f.k.Name()]
	}

	for _, s := range requestValue {
		IP := net.ParseIP(s)
		if IP == nil {
			panic(fmt.Errorf("invalid IP address '%v'", s))
		}

		IPs = append(IPs, IP)
	}

	for _, IP := range IPs {
		for _, IPNet := range f.values {
			if IPNet.Contains(IP) {
				return true
			}
		}
	}

	return false
}
1225728
func IpFormat(ip string) string {
	ipObj := net.ParseIP(ip)
	// Return the ip/host as is if it's either a hostname or an IPv4 address.
	if ipObj == nil || ipObj.To4() != nil {
		return ip
	}

	return fmt.Sprintf("[%s]", ip)
}
1080378
func (ip IP) Equal(eip IP) bool {
	return ip.IP().Equal(eip.IP())
}
1252895
func (c *Context) IP() net.IP {

	var i int
	var s string

	s = "X-Real-IP"
	for i = 0; i < 3; i++ {
		if i == 1 {
			s = strings.ToLower(s)
		}
		if i == 2 {
			s = strings.ToUpper(s)
		}
		if ip := c.Request().Header().Get(s); ip != "" {
			return net.ParseIP(ip)
		}
	}

	s = "X-Forwarded-For"
	for i = 0; i < 3; i++ {
		if i == 1 {
			s = strings.ToLower(s)
		}
		if i == 2 {
			s = strings.ToUpper(s)
		}
		if ip := c.Request().Header().Get(s); ip != "" {
			return net.ParseIP(strings.Split(ip, ", ")[0])
		}
	}

	addr := c.Request().RemoteAddr
	addr, _, _ = net.SplitHostPort(addr)
	return net.ParseIP(addr)

}
350825
func (ctx *Context) IP(trustedProxy ...bool) net.IP {
	trusted := ctx.Setting(SetTrustedProxy).(bool)
	if len(trustedProxy) > 0 {
		trusted = trustedProxy[0]
	}

	if trusted {
		ip := ctx.Req.Header.Get(HeaderXForwardedFor)
		if ip == "" {
			ip = ctx.Req.Header.Get(HeaderXRealIP)
		} else if i := strings.IndexByte(ip, ','); i >= 0 {
			ip = ip[0:i]
		}

		if realIP := net.ParseIP(ip); realIP != nil {
			return realIP
		}
	}

	ra := ctx.Req.RemoteAddr
	ra, _, _ = net.SplitHostPort(ra)
	return net.ParseIP(ra)
}
15276
func (h *HTTPBin) IP(w http.ResponseWriter, r *http.Request) {
	body, _ := json.Marshal(&ipResponse{
		Origin: getOrigin(r),
	})
	writeJSON(w, body, http.StatusOK)
}
1348679
func ip(ctx context.Context) (string, error) {
	req, err := http.NewRequest("GET", "http://api.ipify.org?format=text", nil)
	if err != nil {
		return "", err
	}
	req.Header.Set("X-Request-ID", httpx.RequestID(ctx))

	retrier := retry.NewRetrier("ip", retry.DefaultBackOffOpts, retry.RetryOnAnyError)
	val, err := retrier.Retry(func() (interface{}, error) { return http.DefaultClient.Do(req) })
	if err != nil {
		return "", err
	}
	resp := val.(*http.Response)
	defer resp.Body.Close()

	raw, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return "", err
	}

	return string(raw), nil
}