org.jppf.utils
Class NetworkUtils

java.lang.Object
  extended by 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

Nested Class Summary
static class NetworkUtils.SubnetInformation
          A pair grouping an InetAddress and the corresponding subnet mask length.
 
Method Summary
static List<NetworkUtils.SubnetInformation> getAllNonLocalSubnetInfo()
          Get a NetworkUtils.SubnetInformation object for each non local address of the currrent host.
static String getHostName(String ip)
          Attempt to resolve an IP address into a host name.
static List<InetAddress> getIPV4Addresses()
          Get a list of all known IP v4 addresses for the current host.
static List<InetAddress> getIPV6Addresses()
          Get a list of all known IP v6 addresses for the current host.
static String getManagementHost()
          Get the management host specified in the configuration file.
static String getNonLocalHostAddress()
          Get the non local (meaning neither localhost or loopback) address of the current host.
static List<InetAddress> getNonLocalIPAddresses()
          Get a list of all known non-local IP v4 and v6 addresses for the current host.
static List<InetAddress> getNonLocalIPV4Addresses()
          Get a list of all known non-local IP v4 addresses for the current host.
static List<InetAddress> getNonLocalIPV6Addresses()
          Get a list of all known non-local IP v4 addresses for the current host.
static int getSubnetMaskLength(InetAddress addr)
          Get the subnet mask length of a given address.
static boolean isSameSubnet(NetworkUtils.SubnetInformation si1, NetworkUtils.SubnetInformation si2)
          Determine whether the 2 specified IP addresses are on the same subnet.
static void main(String... args)
          Main entry point.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

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.

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.

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.

getAllNonLocalSubnetInfo

public static List<NetworkUtils.SubnetInformation> getAllNonLocalSubnetInfo()
Get a NetworkUtils.SubnetInformation object for each non local address of the currrent host.

Returns:
a list of NetworkUtils.SubnetInformation instance. This list may be empty, but never null.

isSameSubnet

public static boolean isSameSubnet(NetworkUtils.SubnetInformation si1,
                                   NetworkUtils.SubnetInformation si2)
Determine whether the 2 specified IP addresses are on the same subnet.

Parameters:
si1 - the first IP address to compare.
si2 - the second IP address to compare.
Returns:
true if the 2 addreses are on the same subnet, false otherwise.

main

public static void main(String... args)
Main entry point.

Parameters:
args - not used.


Copyright © 2005-2010 JPPF Team.