MCPcopy Index your code
hub / github.com/keploy/keploy / GetContainerIPv4

Function GetContainerIPv4

utils/utils.go:1640–1679  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1638}
1639
1640func GetContainerIPv4() (string, error) {
1641 // Get all network interfaces
1642 interfaces, err := net.Interfaces()
1643 if err != nil {
1644 return "", err
1645 }
1646
1647 // Iterate over the interfaces
1648 for _, i := range interfaces {
1649 // Skip down or loopback interfaces
1650 if i.Flags&net.FlagUp == 0 || i.Flags&net.FlagLoopback != 0 {
1651 continue
1652 }
1653
1654 // Get the addresses for the current interface
1655 addrs, err := i.Addrs()
1656 if err != nil {
1657 continue
1658 }
1659
1660 // Iterate over the addresses
1661 for _, addr := range addrs {
1662 var ip net.IP
1663 // The address can be of type *net.IPNet or *net.IPAddr
1664 if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
1665 // Check if it's an IPv4 address
1666 if ipnet.IP.To4() != nil {
1667 ip = ipnet.IP
1668 }
1669 }
1670
1671 if ip != nil {
1672 // Found a valid IPv4 address, return it
1673 return ip.String(), nil
1674 }
1675 }
1676 }
1677
1678 return "", fmt.Errorf("could not find a non-loopback IP for the container")
1679}
1680
1681// GetFullCommandUsed returns the full command-line used to run the current process.
1682// It reconstructs the command from os.Args, adding quoting for arguments with spaces or quotes.

Callers 3

HookMethod · 0.92
loadMethod · 0.92
GetProxyInfoMethod · 0.92

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected