1

I am trying to ping www.google.com in my office network but it is not pinging. Code which i am using is as follows:

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class demo1 {

    public static void main(String[] args) throws UnknownHostException, IOException {
        try {           
            String  address = InetAddress.getByName("www.google.com").getHostAddress();
            InetAddress inet = InetAddress.getByName(address);          
            System.out.println("Sending Ping Request to " + address);
            if(inet.isReachable(50000)){
                System.out.println("Host is reachable");
            }
            else{
                System.out.println("Host is not reachable");
            }           
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

I dont know what is the issue. It cant ping to www.facebook.com or www.youtube.com. I get "Host is not reachable" but it can ping to my office internal systems. In the browser all these external systems like google.com opens but Why it can't ping, I don't know. So, can anyone please help me with this?

eltabo
  • 3,749
  • 1
  • 21
  • 33
user3309461
  • 11
  • 1
  • 2

1 Answers1

0

There are many other preferred methods of pinging a server, and it appears like isReachable() has some definite design flaws. This has been addressed here: Why does InetAddress.isReachable return false, when I can ping the IP address?

Community
  • 1
  • 1
JD Davis
  • 3,517
  • 4
  • 28
  • 61