MCPcopy Create free account
hub / github.com/Threadfin/Threadfin / resolveHostIP

Function resolveHostIP

src/toolchain.go:339–385  ·  view source on GitHub ↗

Netzwerk

()

Source from the content-addressed store, hash-verified

337
338// Netzwerk
339func resolveHostIP() error {
340 interfaces, err := net.Interfaces()
341 if err != nil {
342 return err
343 }
344
345 for _, iface := range interfaces {
346 addrs, err := iface.Addrs()
347 if err != nil {
348 return err
349 }
350
351 for _, addr := range addrs {
352 networkIP, ok := addr.(*net.IPNet)
353 System.IPAddressesList = append(System.IPAddressesList, networkIP.IP.String())
354
355 if ok {
356 ip := networkIP.IP.String()
357
358 if networkIP.IP.To4() != nil {
359 // Skip unwanted IPs
360 if !strings.HasPrefix(ip, "169.254") {
361 System.IPAddressesV4 = append(System.IPAddressesV4, ip)
362 System.IPAddress = ip
363 }
364 } else {
365 System.IPAddressesV6 = append(System.IPAddressesV6, ip)
366 }
367 }
368 }
369 }
370
371 if len(System.IPAddress) == 0 {
372 if len(System.IPAddressesV4) > 0 {
373 System.IPAddress = System.IPAddressesV4[0]
374 } else if len(System.IPAddressesV6) > 0 {
375 System.IPAddress = System.IPAddressesV6[0]
376 }
377 }
378
379 System.Hostname, err = os.Hostname()
380 if err != nil {
381 return err
382 }
383
384 return nil
385}
386
387// Sonstiges
388func randomString(n int) string {

Callers 1

InitFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected