java - How to check if the computer is connected to the internet? -


I have seen that this question was asked earlier in the SO. There are some threads:

  • .
  • All these threads are very old. The methods that are defined are:

    • openConnection () by a HTTPRPL connection .
    • Open InetAddress.isReachable .
    • Implementing the ping command through the process and processing the output.

      I have noticed that if I use the second approach to check connectivity with www.google.com then it is returning incorrectly, The result of which should not be. But the first method works, I can not use it in the final way because the defendant himself said it.

      I have also seen the following methods:

        is related to the private boolean (socket socket, string address) {if (socket == empty) {new null pointer exception (" Socket can not be empty "); } {InetSocketAddress inetSocketAddress = try New InetSocketAddress (address, 80); socket.connect (inetSocketAddress); Back true; } Catch (Iron cause) {LOGGER.error (cause.getMessage (), Reason); return false; }}   

      In this way, I am getting the right output, the above sources said that if the computer is connected to the Internet or not, there is no proper way to validate it. But since these threads are outdated, I am hoping that there can be a new way through which I can get what I want. Besides, I must also keep in mind that there are several ways to access the internet like LAN, broadband, dial up, DSL etc. and some servers can block ping access or block certain IPs.

      Any suggestion will be very useful, you can use the NetworkInterface class, there is an isUp () method that gives the boolean, which indicates whether it is special or not. The interface is up and running (which can indicate that it is used for internet connection).

      API:

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -