dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Java
Expertise: Intermediate
Aug 21, 2006

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Ping with J2SE 1.5.0

The following code shows you how to simulate the "ping" command with the J2SE Tiger InetAddress.isReachable method.

import java.io.*;
import java.net.*;

public class reachable{
  public static void main(String args[]) {
  String[] addrs=        
        {"www.java.sun.com","www.yahoo.com","www.google.com"};
    try{
       for(int i=0;i<addrs.length;i++)
               {
               InetAddress addr=InetAddress.getByName(addrs[i]);
               System.out.println("Name:"+addr.getHostName());
               System.out.println("Addr:"+addr.getHostAddress());

               //the address will be checked for 5005 miliseconds
               System.out.println("Reach:"+addr.isReachable(5005));
               }
           }catch(UnknownHostException e){           
              System.out.println(e.getMessage());
           }catch(IOException e){
              System.err.println(e.getMessage());
         }
     }
   }
Leonard Anghel
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date