Class NetworkHelper
java.lang.Object
org.sentrysoftware.metricshub.engine.common.helpers.NetworkHelper
Helper class to retrieve network information.
-
Method Summary
Modifier and TypeMethodDescriptionstatic URLConstructs a URL from the specified protocol, hostname or IP address, and port.static StringGet the fully qualified domain name (FQDN) of the given hostname.static booleanisLocalhost(String hostname) Check whether the given hostname is a localhost.static StringresolveDns(String hostname) Resolve the IP address of the given hostname.
-
Method Details
-
isLocalhost
Check whether the given hostname is a localhost.- Parameters:
hostname- The hostname to check.- Returns:
trueif the hostname is a localhost,falseotherwise.
-
resolveDns
Resolve the IP address of the given hostname.- Parameters:
hostname- The hostname.- Returns:
- The IP address of the hostname, or
nullif not resolved.
-
getFqdn
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 IPv6portNumber- The port number- Returns:
- a URL object constructed from the provided parameters
- Throws:
MalformedURLException- if no protocol is specified, or an unknown protocol is foundUnknownHostException- if the IP address or hostname cannot be resolvedURISyntaxException- if the URI string constructed from the input parameters is syntactically incorrect
-