java.lang.Object
org.sentrysoftware.metricshub.engine.common.helpers.NetworkHelper

public class NetworkHelper extends Object
Helper class to retrieve network information.
  • Method Details

    • isLocalhost

      public static boolean isLocalhost(String hostname)
      Check whether the given hostname is a localhost.
      Parameters:
      hostname - The hostname to check.
      Returns:
      true if the hostname is a localhost, false otherwise.
    • resolveDns

      public static String resolveDns(String hostname)
      Resolve the IP address of the given hostname.
      Parameters:
      hostname - The hostname.
      Returns:
      The IP address of the hostname, or null if not resolved.
    • getFqdn

      public static String getFqdn(String hostname)
      Get the fully qualified domain name (FQDN) of the given hostname.
      Parameters:
      hostname - The hostname.
      Returns:
      The FQDN of the hostname, or the original hostname if not resolved.
    • createUrl

      public static URL createUrl(@NonNull @NonNull String protocol, @NonNull @NonNull String hostnameOrIp, @NonNull @NonNull Integer portNumber) throws MalformedURLException, UnknownHostException, URISyntaxException
      Constructs a URL from the specified protocol, hostname or IP address, and port. It properly formats the URL for both IPv4 and IPv6 addresses.
      Parameters:
      protocol - The communication protocol (e.g., "http", "https")
      hostnameOrIp - The host name or IP address, IPv4 or IPv6
      portNumber - The port number
      Returns:
      a URL object constructed from the provided parameters
      Throws:
      MalformedURLException - if no protocol is specified, or an unknown protocol is found
      UnknownHostException - if the IP address or hostname cannot be resolved
      URISyntaxException - if the URI string constructed from the input parameters is syntactically incorrect