Class NetworkUtils

java.lang.Object
org.jppf.utils.NetworkUtils

public final class NetworkUtils extends Object
Utility class that provides method to discover the network configuration of the current machine.
Author:
Laurent Cohen
  • Method Details

    • getNonLocalHostAddress

      public static String getNonLocalHostAddress()
      Get the non local (meaning neither localhost or loopback) address of the current host.
      Returns:
      the ipv4 address as a string.
    • getIPV4Addresses

      public static List<InetAddress> getIPV4Addresses()
      Get a list of all known IP v4 addresses for the current host.
      Returns:
      a List of InetAddress instances, may be empty but never null.
    • getNonLocalIPV4Addresses

      public static List<InetAddress> getNonLocalIPV4Addresses()
      Get a list of all known non-local IP v4 addresses for the current host.
      Returns:
      a List of InetAddress instances, may be empty but never null.
    • getIPV6Addresses

      public static List<InetAddress> getIPV6Addresses()
      Get a list of all known IP v6 addresses for the current host.
      Returns:
      a List of Inet6Address instances, may be empty but never null.
    • getNonLocalIPV6Addresses

      public static List<InetAddress> getNonLocalIPV6Addresses()
      Get a list of all known non-local IP v4 addresses for the current host.
      Returns:
      a List of InetAddress instances, may be empty but never null.
    • getNonLocalIPAddresses

      public static List<InetAddress> getNonLocalIPAddresses()
      Get a list of all known non-local IP v4 and v6 addresses for the current host.
      Returns:
      a List of InetAddress instances, may be empty but never null.
    • getManagementHost

      public static String getManagementHost()
      Get the management host specified in the configuration file.
      Returns:
      the host as a string.
    • retrieveManagementHostOrLocalhost

      public static String retrieveManagementHostOrLocalhost()
      Get the management host specified in the configuration file.
      Returns:
      the host as a string.
    • getHostName

      public static String getHostName(String ip)
      Attempt to resolve an IP address into a host name.
      Parameters:
      ip - the ip address to resolve.
      Returns:
      the corresponding host name, or its IP if the name could not be resolved.
    • getHostIP

      public static HostIP getHostIP(String hostOrIP)
      Attempt to resolve an IP address or host name into a (host name, ip address) pair.
      Parameters:
      hostOrIP - the ip address to resolve.
      Returns:
      a HostIP instance.
      Since:
      5.0
    • getSubnetMaskLength

      public static int getSubnetMaskLength(InetAddress addr)
      Get the subnet mask length of a given address.
      Parameters:
      addr - the address for which to get the subnet mask.
      Returns:
      the length (number of bits set to 1) for the corresponding subnet mask.
    • main

      public static void main(String... args)
      Main entry point.
      Parameters:
      args - not used.
    • toIntArray

      public static int[] toIntArray(InetAddress addr)
      Convert an IP address int array.
      Parameters:
      addr - the source address to convert.
      Returns:
      an array of int values, or null if the source could not be parsed.
    • isIPv6Address

      public static boolean isIPv6Address(String host)
      Determine whether a textual address is an IP address (as opposed ot a host name) in IPv6 format.
      Parameters:
      host - the textual representation of the address.
      Returns:
      true if the textual address is an IP address in IPv6 format, false otherwise.
    • parseAddresses

      public static HostIP[] parseAddresses(String addresses)
      Parse a list of addresses.
      Parameters:
      addresses - a string containing a space-separated list of host_name|ip_address pairs.
      Returns:
      an array on HostIP instances.
    • getInetAddress

      public static InetAddress getInetAddress(String propertyPrefix)
      Parameters:
      propertyPrefix - prefix for the properties deifining include and exclude IP address patterns.
      Returns:
      an InetAddress to bind to, or null to bind to all interfaces.
    • getInetAddress

      public static InetAddress getInetAddress(TypedProperties config, String propertyPrefix)
      Parameters:
      config - the config to use.
      propertyPrefix - prefix for the properties deifining include and exclude IP address patterns.
      Returns:
      an InetAddress to bind to, or null to bind to all interfaces.