public final class UtlNet extends Object
This class MAY be used by end users, however it is not supported.
Modifier and Type | Class and Description |
---|---|
static interface |
UtlNet.DebugTracer |
Constructor and Description |
---|
UtlNet() |
Modifier and Type | Method and Description |
---|---|
static String |
formatNetworkInterfaceDescriptor(NetworkInterface nif)
Returns a string describing a network interface (name + all bound addresses)
|
static NetworkInterface |
getFirstActiveNetworkInterface(boolean multicastRequired)
Find an active, non-virtual, non-loopback network device that might be appropriate as a primary device for
general network communication and/or discovery.
|
static NetworkInterface |
getFirstActiveNetworkInterface(UtlNet.DebugTracer tracer,
boolean multicastRequired)
Find an active, non-virtual, non-loopback network device that might be appropriate as a primary device for
general network communication and/or discovery.
|
static InetAddress |
getFirstInetAddress(NetworkInterface networkInterface)
Given a
NetworkInterface , returns the first InetAddress associated with the
interface (prioritizing IPv4 over IPv6). |
static String |
getHostName(InetAddress address)
Resolves the host name for the provided address.
|
static String |
getLocalHostAddress()
Get the local host address
This method returns the local host address using the following:
- InetAddress.getLocalHost().getHostAddress . |
static String |
getLocalHostAddressForDisplay(String defaultValue)
Get the local host address for display purposes.
|
static InetAddress |
getLocalHostInetAddress()
Get the
InetAddress representing the local host IP + hostname. |
static String |
getLocalHostName()
Get the local host name
This method returns the local host name using the following:
- InetAddress.getLocalHost().getHostName . |
static String |
getLocalHostNameForDisplay(String defaultValue)
Get the local host name for display purposes.
|
static String |
inetAddrToName(String addr)
Get a host name corresponding to a inet network address.
|
static boolean |
isAddressLocal(InetAddress addr)
Tests if a given address is local to current host.
|
public static final String inetAddrToName(String addr)
addr
- The textual representation of the inet network address.IllegalArgumentException
- Thrown in case the user has either
supplied an inet address in the incorrect format or has provided
a host name that cannot be resolved to an IP address.
This method resolves a textual representation of an inet address to its host name. In case a host name is provided in the addr parameter, this method will attempt to resolve the name to an IP address and then resolve it back to the host name.
public static final String getHostName(InetAddress address)
address
- The address whose host name to look up.public static final NetworkInterface getFirstActiveNetworkInterface(boolean multicastRequired) throws SocketException
multicastRequired
- indicates whether the returned network interface must support multicastSocketException
- if there is an error getting the list of candidate network devicespublic static final NetworkInterface getFirstActiveNetworkInterface(UtlNet.DebugTracer tracer, boolean multicastRequired) throws SocketException
multicastRequired
- indicates whether the returned network interface must support multicasttracer
- the tracer to use for logging, may be null if no logging is requiredSocketException
- if there is an error getting the list of candidate network devicespublic static final InetAddress getFirstInetAddress(NetworkInterface networkInterface)
NetworkInterface
, returns the first InetAddress
associated with the
interface (prioritizing IPv4 over IPv6).networkInterface
- The network interface to inspectpublic static final String formatNetworkInterfaceDescriptor(NetworkInterface nif)
public static boolean isAddressLocal(InetAddress addr)
addr
- The address to test.public static final InetAddress getLocalHostInetAddress() throws UnknownHostException
InetAddress
representing the local host IP + hostname.UnknownHostException
- Thrown if a local InetAddress could not
be determined.public static final String getLocalHostNameForDisplay(String defaultValue)
defaultValue
- The value to return if a local host name could not be
determined.
This method returns the name of the local host machine on which the X process is running. The defaultValue is returned if the local host name could not be determined for whatever reason
public static final String getLocalHostName() throws UnknownHostException
This method returns the local host name using the following:
- InetAddress.getLocalHost().getHostName
.
If a host name could not be determined, then this method throws
an UnknownHostException exception.
UnknownHostException
- Thrown if the local host name could not
be determined via InetAddress.getLocalHost().getHostName
public static final String getLocalHostAddressForDisplay(String defaultValue)
defaultValue
- The value to return if a local host address could not be
determined.
This method returns the address of the local host machine on which the X process
is running as returned by InetAddress.getLocalHost().getHostAddress
.
The defaultValue is returned if the local host address could not be determined
for whatever reason
public static final String getLocalHostAddress() throws UnknownHostException
This method returns the local host address using the following:
- InetAddress.getLocalHost().getHostAddress
.
If a host address could not be determined, then this method throws
an UnknownHostException exception.
UnknownHostException
- Thrown if the local host address could not
be determined via InetAddress.getLocalHost().getHostAddress
Copyright © 2019 Neeve Research, LLC. All Rights Reserved.