Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: Ping from JAVA to IP Address Date: Mon, 24 Oct 2011 20:26:22 +0200 Lines: 61 Message-ID: <9gloupFf3oU1@mid.individual.net> References: <670cd44b-d05f-4300-9c59-b26f28e17323@j36g2000prh.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net hJ6cxiYcQO8bTH0g3Mcz6QsTfk7nrxOAZuIP7pVaGpEcj/2KE= Cancel-Lock: sha1:4QeLj18JwGe1O/A1HKY6LR8jy2Y= User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 In-Reply-To: <670cd44b-d05f-4300-9c59-b26f28e17323@j36g2000prh.googlegroups.com> Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9149 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/