Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #9174

Re: Ping from JAVA to IP Address

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From markspace <-@.>
Newsgroups comp.lang.java.programmer
Subject Re: Ping from JAVA to IP Address
Date Tue, 25 Oct 2011 08:12:30 -0700
Organization A noiseless patient Spider
Lines 30
Message-ID <j86jl3$tvd$1@dont-email.me> (permalink)
References <670cd44b-d05f-4300-9c59-b26f28e17323@j36g2000prh.googlegroups.com> <9gloupFf3oU1@mid.individual.net> <j84mmv$6b7$1@dont-email.me> <0aec9e49-b7d2-4afd-9f8f-07a2d07392ca@k13g2000prg.googlegroups.com> <26b57282-aa91-4116-884c-92af6ae1f911@k38g2000pro.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Tue, 25 Oct 2011 15:12:35 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="XjIWM99mD7Ijfdu600oVPA"; logging-data="30701"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+U+a0zl29cGqWBu0jNDN6kaHcB5XNU064="
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1
In-Reply-To <26b57282-aa91-4116-884c-92af6ae1f911@k38g2000pro.googlegroups.com>
Cancel-Lock sha1:enZMUSqpR5dHR8sS90y04Yo4Mkw=
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9174

Show key headers only | View raw


On 10/25/2011 1:56 AM, sahm wrote:
> All I want to do is simple function that can check if there is
> Internet connection or Not ?


Doesn't work for me either, and I'm not sure why.  Try opening an HTTP 
socket on a well known address.  Can anybody supply a public host name 
that doesn't talk on port 80 so I can test this works ok when there's no 
internet connection?

public class PingTest {

    private static String pingVectors[] =
    { "cnn.com", "google.com", };

    public static void main(String[] args)
            throws UnknownHostException, IOException
    {
       for( String s : pingVectors ) {
          InetAddress ia = InetAddress.getByName(s);
          boolean reachable = ia.isReachable(6000);
          System.out.println(s+" is reachable: " + reachable);

          Socket sock = new Socket( s , 80 );
          sock.getOutputStream();
          sock.close();
          System.out.println(s+" opened socket ok");
       }
    }
}

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Ping from JAVA to IP Address sahm <sahm007@gmail.com> - 2011-10-24 11:01 -0700
  Re: Ping from JAVA to IP Address Robert Klemme <shortcutter@googlemail.com> - 2011-10-24 20:26 +0200
    Re: Ping from JAVA to IP Address markspace <-@.> - 2011-10-24 14:52 -0700
      Re: Ping from JAVA to IP Address sahm <sahm007@gmail.com> - 2011-10-24 22:31 -0700
        Re: Ping from JAVA to IP Address sahm <sahm007@gmail.com> - 2011-10-25 01:56 -0700
          Re: Ping from JAVA to IP Address Screamin Lord Byron <scre@min.dot> - 2011-10-25 11:57 +0200
          Re: Ping from JAVA to IP Address markspace <-@.> - 2011-10-25 08:12 -0700
            Re: Ping from JAVA to IP Address Screamin Lord Byron <scre@min.dot> - 2011-10-25 22:13 +0200
              Re: Ping from JAVA to IP Address markspace <-@.> - 2011-10-25 16:02 -0700
                Re: Ping from JAVA to IP Address Screamin Lord Byron <scre@min.dot> - 2011-10-26 13:16 +0200
              Re: Ping from JAVA to IP Address Arne Vajhøj <arne@vajhoej.dk> - 2011-11-06 15:29 -0500
                Re: Ping from JAVA to IP Address glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2011-12-07 08:59 +0000
  Re: Ping from JAVA to IP Address Roedy Green <see_website@mindprod.com.invalid> - 2011-10-25 21:28 -0700
  Re: Ping from JAVA to IP Address Arne Vajhøj <arne@vajhoej.dk> - 2011-11-06 15:36 -0500

csiph-web