Package org.jppf.utils
Class NetworkUtils
java.lang.Object
org.jppf.utils.NetworkUtils
Utility class that provides method to discover the network configuration of the current machine.
- Author:
- Laurent Cohen
-
Method Summary
Modifier and TypeMethodDescriptionstatic HostIPAttempt to resolve an IP address or host name into a (host name, ip address) pair.static StringgetHostName(String ip) Attempt to resolve an IP address into a host name.static InetAddressgetInetAddress(String propertyPrefix) static InetAddressgetInetAddress(TypedProperties config, String propertyPrefix) static List<InetAddress>Get a list of all known IP v4 addresses for the current host.static List<InetAddress>Get a list of all known IP v6 addresses for the current host.static StringGet the management host specified in the configuration file.static StringGet the non local (meaning neither localhost or loopback) address of the current host.static List<InetAddress>Get a list of all known non-local IP v4 and v6 addresses for the current host.static List<InetAddress>Get a list of all known non-local IP v4 addresses for the current host.static List<InetAddress>Get a list of all known non-local IP v4 addresses for the current host.static intGet the subnet mask length of a given address.static booleanisIPv6Address(String host) Determine whether a textual address is an IP address (as opposed ot a host name) in IPv6 format.static voidMain entry point.static HostIP[]parseAddresses(String addresses) Parse a list of addresses.static StringGet the management host specified in the configuration file.static int[]toIntArray(InetAddress addr) Convert an IP address int array.
-
Method Details
-
getNonLocalHostAddress
Get the non local (meaning neither localhost or loopback) address of the current host.- Returns:
- the ipv4 address as a string.
-
getIPV4Addresses
Get a list of all known IP v4 addresses for the current host.- Returns:
- a List of
InetAddressinstances, may be empty but never null.
-
getNonLocalIPV4Addresses
Get a list of all known non-local IP v4 addresses for the current host.- Returns:
- a List of
InetAddressinstances, may be empty but never null.
-
getIPV6Addresses
Get a list of all known IP v6 addresses for the current host.- Returns:
- a List of
Inet6Addressinstances, may be empty but never null.
-
getNonLocalIPV6Addresses
Get a list of all known non-local IP v4 addresses for the current host.- Returns:
- a List of
InetAddressinstances, may be empty but never null.
-
getNonLocalIPAddresses
Get a list of all known non-local IP v4 and v6 addresses for the current host.- Returns:
- a List of
InetAddressinstances, may be empty but never null.
-
getManagementHost
Get the management host specified in the configuration file.- Returns:
- the host as a string.
-
retrieveManagementHostOrLocalhost
Get the management host specified in the configuration file.- Returns:
- the host as a string.
-
getHostName
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
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
HostIPinstance. - Since:
- 5.0
-
getSubnetMaskLength
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
Main entry point.- Parameters:
args- not used.
-
toIntArray
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
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:
trueif the textual address is an IP address in IPv6 format,falseotherwise.
-
parseAddresses
Parse a list of addresses.- Parameters:
addresses- a string containing a space-separated list of host_name|ip_address pairs.- Returns:
- an array on
HostIPinstances.
-
getInetAddress
- Parameters:
propertyPrefix- prefix for the properties deifining include and exclude IP address patterns.- Returns:
- an
InetAddressto bind to, ornullto bind to all interfaces.
-
getInetAddress
- Parameters:
config- the config to use.propertyPrefix- prefix for the properties deifining include and exclude IP address patterns.- Returns:
- an
InetAddressto bind to, ornullto bind to all interfaces.
-