Detect internet Connection using Java [duplicate]

That’s a perfectly reasonable approach to solving the problem. The bad thing is that you are really testing DNS rather than testing the whole network, but in practice you can often get by with treating those as equivalent.

The other thing to remember, is that you will need to set a system property to turn off dns caching in the java runtime. Otherwise it may continue to report that the network is up based upon cached data (even though it is down).

Another approach would be to actually open an HTTP request to some network address such as this every so often.

Leave a Comment