skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Tuesday, October 9, 2012

TRACE ROUTE COMMAND TO KNOW THE EXACT SERVER NAME WHERE THE PACKET GOT FAILED

Posted by Raju Gupta at 1:02 PM – 0 comments
 
It will track the details of each packet being moved from one hop to the other, in the way from Source to Destination.

public static void findTraceRoute(String errorNumber, String hostname)
 {
    String strCmd ="traceroute"+" "+hostname;
   String strHostName= hostname;
   String strResult="";
   String strError="";
   String s = null;
   Process p=null;
   BufferedReader stdInput=null;
   BufferedReader stdError=null;
   
   try {

     // run the Unix command specified in the "strCmd"
  
     p = Runtime.getRuntime().exec(strCmd);
     
     stdInput = new BufferedReader(new
      InputStreamReader(p.getInputStream()));
     
     // read the output from the command
           
      while ((s = stdInput.readLine()) != null) {
        strResult=strResult+s;//Append the output to the strresult String
     }//end of while loop
 //Log the output(strResult) of the TRACE ROUTE Command into the Message.log File
               
   }
    catch (IOException e) {
   
 // read any errors from the attempted command and store it in the strError String
     try
     {
      stdError = new BufferedReader(new
      InputStreamReader(p.getErrorStream()));
       
      while ((s = stdError.readLine()) != null) {
       strError=strError+s;
       }
     }catch(IOException ex){
      
     }
    }finally {
     //Close the Stream Readers
     try
     {
      stdInput.close();
      stdError.close();
    
     } catch(Exception e){
           }
      //Termination of the Process
      p.destroy();
    }//end of finally block
}//end of trace route method

Labels: Java Command Example , Java Network Example

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger