diff --git a/kraken-java-sdk/kraken-java-sdk-core/src/main/java/com/consoleconnect/kraken/operator/core/toolkit/IpUtils.java b/kraken-java-sdk/kraken-java-sdk-core/src/main/java/com/consoleconnect/kraken/operator/core/toolkit/IpUtils.java index be64aa6c..dd4ba1b8 100644 --- a/kraken-java-sdk/kraken-java-sdk-core/src/main/java/com/consoleconnect/kraken/operator/core/toolkit/IpUtils.java +++ b/kraken-java-sdk/kraken-java-sdk-core/src/main/java/com/consoleconnect/kraken/operator/core/toolkit/IpUtils.java @@ -1,5 +1,8 @@ package com.consoleconnect.kraken.operator.core.toolkit; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.UnknownHostException; @@ -53,9 +56,17 @@ public static String getHostAddress() { public static String getFQDN() { try { - InetAddress address = InetAddress.getLocalHost(); - return address.getCanonicalHostName(); - } catch (UnknownHostException e) { + ProcessBuilder builder = new ProcessBuilder(); + builder.command("/usr/bin/bash", "-c", "hostname -f"); + Process process = builder.start(); + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + String line; + StringBuilder result = new StringBuilder(); + while ((line = reader.readLine()) != null) { + result.append(line); + } + return result.toString(); + } catch (IOException e) { return IP_UNKNOWN; } } diff --git a/kraken-java-sdk/kraken-java-sdk-core/src/test/java/com/consoleconnect/kraken/operator/core/IpUtilsTest.java b/kraken-java-sdk/kraken-java-sdk-core/src/test/java/com/consoleconnect/kraken/operator/core/IpUtilsTest.java index bd7e8675..e1ede6b7 100644 --- a/kraken-java-sdk/kraken-java-sdk-core/src/test/java/com/consoleconnect/kraken/operator/core/IpUtilsTest.java +++ b/kraken-java-sdk/kraken-java-sdk-core/src/test/java/com/consoleconnect/kraken/operator/core/IpUtilsTest.java @@ -16,4 +16,10 @@ void givenRequest_whenGetIpAddress_thenReturnIpAddress() { String ip = IpUtils.getIP(request); Assertions.assertNotNull(ip); } + + @Test + void givenECS_whenQueryFQDN_thenReturnSuccess() { + String result = IpUtils.getFQDN(); + Assertions.assertNotEquals("unknown", result); + } }