MCPcopy Create free account
hub / github.com/ddev/ddev / GetLocalIPs

Function GetLocalIPs

pkg/netutil/netutil.go:110–133  ·  view source on GitHub ↗

GetLocalIPs returns IP addresses associated with the machine

()

Source from the content-addressed store, hash-verified

108
109// GetLocalIPs returns IP addresses associated with the machine
110func GetLocalIPs() ([]string, error) {
111 addrs, err := net.InterfaceAddrs()
112 if err != nil {
113 return nil, err
114 }
115
116 var localIPs []string
117 for _, addr := range addrs {
118 switch v := addr.(type) {
119 case *net.IPNet:
120 if v.IP.IsLoopback() || v.IP.To4() == nil {
121 continue
122 }
123 localIPs = append(localIPs, v.IP.String())
124 case *net.IPAddr:
125 if v.IP.IsLoopback() || v.IP.To4() == nil {
126 continue
127 }
128 localIPs = append(localIPs, v.IP.String())
129 }
130 }
131
132 return localIPs, nil
133}
134
135// BaseURLFromFullURL returns the base url (http://hostname.example.com) from a URL, without port
136func BaseURLFromFullURL(fullURL string) string {

Callers 2

IsPortActiveFunction · 0.85
HasLocalIPFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected