1
static void pingTestAndUpdate(String ip) throws UnknownHostException, IOException {
    //Check if pingable
    boolean reachable = false;
    reachable = InetAddress.getByName(ip).isReachable(200);
    String status;
    if (reachable == true) {
        status = "Responding";
    }
    else if (reachable == false) {
        status = "Not responding";
    }
    else {
        status = "Error";
    }

    System.out.println(ip + " is: " + status);
}

The output is:

10.130.72.247 is: Not responding

If I ping the same IP address from the command line, I get:

Pinging 10.130.72.247 with 32 bytes of data:
Reply from 10.130.72.247 bytes=32 time=1ms TTL=128
Reply from 10.130.72.247 bytes=32 time=1ms TTL=128
Reply from 10.130.72.247 bytes=32 time=1ms TTL=128
Reply from 10.130.72.247 bytes=32 time=1ms TTL=128

Ping statistics for 10.130.72.247:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss).
Approximate round trip times in milliseconds:
    Minimum = 1ms, Maximum = 1ms, Average = 1ms

I think this is a issue to do with the subnet 255.255.252.0 we have but I can't find an easy way to solve this, can anyone help me?

static void pingTestAndUpdate(String ip) throws UnknownHostException, IOException {
    //To Check if pingable
    boolean reachable;
        reachable = InetAddress.getByName(ip).isReachable(200);
    System.out.println(ip + " is: " + reachable);
}

This returns false but a ping from cmd to the same address is successful. The result should be true but is currently false even though the address is reachable.

Michael
  • 41,989
  • 11
  • 82
  • 128
Andyg_2020
  • 101
  • 2
  • 7
  • 1
    Do not create screen shots. Your source code is **text**. Your console output is **text**. All of that should be part of your question as nicely formatted text, not as screen shot. So please edit your question. – GhostCat Aug 23 '17 at 08:42
  • 1
    Beyond that, your code doesn't make sense. A boolean is either true or false, so you only need `if (reachable)` + then + else. Nothing *else*. – GhostCat Aug 23 '17 at 08:44
  • status is fed into gui and a log file so it is readable by user and to make the log file easier to understand I have stripped back the GUI and the other functions to try and make the question easier to understand – Andyg_2020 Aug 23 '17 at 08:46
  • @GhostCat Still better than "enter image description here". Also, if you open the image in another tab you'll be able to read everything. The relevant code is included in the question as text, I believe the screenshot was added just to show the error he got in the console. – BackSlash Aug 23 '17 at 08:46
  • @BackSlash The relevant code was only added to the question after I told him to do so. See the very first version of the question. And thing is: when I had that image link, it would open "readable" - now I have to zoom the page to 200 % to get it (not everybody here is 20 years old and has 125% visual acuity ;-) – GhostCat Aug 23 '17 at 08:51
  • @GhostCat Now the code is there, so the question is ok. And honestly if StackOverflow doesn't have a proper image visualization tool it's not my fault. A lot of questions with links to images were commented with "don't link to image, just post it". It's also the default action in the question editor, so I believe that an image should be just embedded in the question itself. Anyway, feel free to edit the question again. – BackSlash Aug 23 '17 at 08:58
  • @BackSlash There are things that can (almost) only expressed using images. But images basically break screen readers. Therefore one should only use them if there is no other way. Stuff that is *text only* does not belong into images. End of story. – GhostCat Aug 23 '17 at 09:20

0 Answers0