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