How do you determine which network interface is connected to the internet using Java? For example, I run
InetAddress.getLocalHost().getHostAddress();
Take a look at Retrieving Network Interfaces and Listing Network Interface Addresses in the Java Tutorial.
If you have several network interfaces which are up and running, you must select programmatically the network interface that your program should use.
UPDATE:
I've found the question that is similar to yours.
See the answer to how-to-check-if-internet-connection-is-present-in-java.
UPDATE 2:
IMHO You should do the following in your program: