public class EgressInterfaceFinder extends Object
Modifier and Type | Class and Description |
---|---|
static class |
EgressInterfaceFinder.EgressResolutionException
An exception representing a failure to determine a default egress
network interface.
|
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_TIMEOUT_MILLIS |
Constructor and Description |
---|
EgressInterfaceFinder() |
Modifier and Type | Method and Description |
---|---|
NetworkInterface |
egressInterface()
Attempt to find the default egress interface on the current system.
|
NetworkInterface |
fromAggregate(com.fasterxml.uuid.EgressInterfaceFinder.Finder[] finders)
Attempt to find the default egress interface on the current system,
by trying each of the specified discovery mechanisms, in order, until
one of them succeeds.
|
NetworkInterface |
fromDefaultMechanisms(int timeoutMillis)
Attempt to find the default egress interface on the current system,
using the specified connection timeout duration.
|
NetworkInterface |
fromLocalAddress(InetAddress localAddress)
Attempt to find the default egress interface on the current system, by
finding a
NetworkInterface that has the specified network
address. |
NetworkInterface |
fromRemoteConnection(int timeoutMillis,
InetSocketAddress remoteAddress)
Attempt to find the default egress interface on the current system,
by connection to the specified address.
|
NetworkInterface |
fromRemoteDatagramSocketConnection(InetSocketAddress remoteAddress)
Attempt to find the default egress interface on the current system,
using the specified connection timeout duration and connecting with
a
DatagramSocket . |
NetworkInterface |
fromRemoteSocketConnection(int timeoutMillis,
InetSocketAddress remoteAddress)
Attempt to find the default egress interface on the current system,
using the specified connection timeout duration and connecting with
a
Socket . |
NetworkInterface |
fromRootNameserverConnection(int timeoutMillis)
Attempt to find the default egress interface on the current system,
by connecting to one of the root name servers (chosen at random).
|
public static final int DEFAULT_TIMEOUT_MILLIS
public NetworkInterface egressInterface() throws EgressInterfaceFinder.EgressResolutionException
This is done on a best efforts basis, as Java does not provide the necessary level of OS integration that is required to do this robustly. However, this utility should do a decent job on Windows, Linux and macOS so long as the local system has a working network connection at the time of execution. If the current system is multihomed with multiple egress interfaces, one such interface will be chosen indeterminately.
Accurately determining the egress interface necessitates us attempting to make outbound network connections. This will be done synchronously and can be a very slow process. You can tune the amount of time allowed to establish the outbound connections by increasing/decreasing the timeout value.
EgressInterfaceFinder.EgressResolutionException
- if an egress interface could not be
determinedpublic NetworkInterface fromDefaultMechanisms(int timeoutMillis) throws EgressInterfaceFinder.EgressResolutionException
This will attempt to connect to one of the root DNS nameservers (chosen randomly), and failing that, simply to IPv4 address 1.1.1.1 and finally IPv6 address 1::1.
timeoutMillis
- the amount of time (milliseconds) allowed to
establish an outbound connectionEgressInterfaceFinder.EgressResolutionException
- if an egress interface could not be
determinedpublic NetworkInterface fromAggregate(com.fasterxml.uuid.EgressInterfaceFinder.Finder[] finders) throws EgressInterfaceFinder.EgressResolutionException
finders
- array of finder callbacks to be executedEgressInterfaceFinder.EgressResolutionException
- if an egress interface could not be
determinedpublic NetworkInterface fromRootNameserverConnection(int timeoutMillis) throws EgressInterfaceFinder.EgressResolutionException
timeoutMillis
- the amount of time (milliseconds) allowed to
establish an outbound connectionEgressInterfaceFinder.EgressResolutionException
- if an egress interface could not be
determinedpublic NetworkInterface fromRemoteConnection(int timeoutMillis, InetSocketAddress remoteAddress) throws EgressInterfaceFinder.EgressResolutionException
DatagramSocket
, which seems to work well for Windows
& Linux, and is faster to uses than Socket
as opening one does
not actually require negotiate a handshake connection, but this does
not appear to work on MacOS
Socket
, which seems to work better for MacOS, but
needs to actually negotiate a connection handshake from a remote host
timeoutMillis
- the amount of time (milliseconds) allowed to
establish an outbound connectionremoteAddress
- the address to which a connection will be attempted
in order to determine which interface is used to
connectEgressInterfaceFinder.EgressResolutionException
- if an egress interface could not be
determinedpublic NetworkInterface fromRemoteSocketConnection(int timeoutMillis, InetSocketAddress remoteAddress) throws EgressInterfaceFinder.EgressResolutionException
Socket
.timeoutMillis
- the amount of time (milliseconds) allowed to
establish an outbound connectionremoteAddress
- the address to which a connection will be attempted
in order to determine which interface is used to
connectEgressInterfaceFinder.EgressResolutionException
- if an egress interface could not be
determinedpublic NetworkInterface fromRemoteDatagramSocketConnection(InetSocketAddress remoteAddress) throws EgressInterfaceFinder.EgressResolutionException
DatagramSocket
.remoteAddress
- the address to which a connection will be attempted
in order to determine which interface is used to
connectEgressInterfaceFinder.EgressResolutionException
- if an egress interface could not be
determinedpublic NetworkInterface fromLocalAddress(InetAddress localAddress) throws EgressInterfaceFinder.EgressResolutionException
NetworkInterface
that has the specified network
address. If more than one interface has the specified address, then
one of them will be selected indeterminately.localAddress
- the local address which is assigned to an interfaceEgressInterfaceFinder.EgressResolutionException
- if an egress interface could not be
determinedCopyright © 2023 FasterXML.com. All rights reserved.