GetIPAddress attempts to find the best-available IP address. It first tries to get the public IP address, and if that fails, it falls back to getting the local outbound IP address. Returns: - string: The determined IP address (preferring public IPv4)
()
| 97 | // Returns: |
| 98 | // - string: The determined IP address (preferring public IPv4) |
| 99 | func GetIPAddress() string { |
| 100 | publicIP, err := getPublicIP() |
| 101 | if err == nil { |
| 102 | log.Debugf("Public IP detected: %s", publicIP) |
| 103 | return publicIP |
| 104 | } |
| 105 | log.Warnf("Failed to get public IP, falling back to outbound IP: %v", err) |
| 106 | outboundIP, err := getOutboundIP() |
| 107 | if err == nil { |
| 108 | log.Debugf("Outbound IP detected: %s", outboundIP) |
| 109 | return outboundIP |
| 110 | } |
| 111 | log.Errorf("Failed to get any IP address: %v", err) |
| 112 | return "127.0.0.1" // Fallback |
| 113 | } |
| 114 | |
| 115 | // PrintSSHTunnelInstructions detects the IP address and prints SSH tunnel instructions |
| 116 | // for the user to connect to the local OAuth callback server from a remote machine. |
no test coverage detected