MCPcopy Create free account
hub / github.com/kataras/iris / GetIPAddress

Function GetIPAddress

core/netutil/ip.go:44–59  ·  view source on GitHub ↗

GetIPAddress returns a valid public IP Address from a collection of IP Addresses and a range of private subnets. Reports whether a valid IP was found.

(ipAddresses []string, privateRanges []IPRange)

Source from the content-addressed store, hash-verified

42//
43// Reports whether a valid IP was found.
44func GetIPAddress(ipAddresses []string, privateRanges []IPRange) (string, bool) {
45 // march from right to left until we get a public address
46 // that will be the address right before our proxy.
47 for i := len(ipAddresses) - 1; i >= 0; i-- {
48 ip := strings.TrimSpace(ipAddresses[i])
49 realIP := net.ParseIP(ip)
50 if !realIP.IsGlobalUnicast() || IPIsPrivateSubnet(realIP, privateRanges) {
51 // bad address, go to next
52 continue
53 }
54 return ip, true
55
56 }
57
58 return "", false
59}

Callers 2

RemoteAddrMethod · 0.92
TestIPFunction · 0.85

Calls 1

IPIsPrivateSubnetFunction · 0.85

Tested by 1

TestIPFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…