Traceroute on Windows in Java

Traceroute is a computer network diagnostic tool for displaying the route (path) and measuring transit delays of packets across an Internet Protocol (IP) network

Source code :

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

class Traceroute
{
    public static void main(String args[]){

    BufferedReader in;

        try{
            Runtime r   =   Runtime.getRuntime();
            Process p   =   r.exec("tracert www.google.com");

            in  =   new BufferedReader(new InputStreamReader(p.getInputStream()));

            String line;

            if(p==null)
                System.out.println("could not connect");

            while((line=in.readLine())!=null){

                System.out.println(line);

                //in.close();
            }

        }catch(IOException e){

        System.out.println(e.toString());

        }
    }
}

Output :

Tracing route to www.google.com [74.125.28.106]
over a maximum of 30 hops:

  1    70 ms    55 ms    70 ms  10.228.129.13
  2            87 ms    84 ms  10.228.149.14
  3    82 ms    85 ms          116.202.226.145
  4    95 ms    94 ms   136 ms  10.228.158.82
  5                          Request timed out.
  6    53 ms    55 ms    59 ms  116.202.226.21
  7    85 ms    74 ms    82 ms  72.14.205.145
  8    76 ms    75 ms    71 ms  72.14.235.69
  9   124 ms   114 ms   113 ms  216.239.63.213
 10   181 ms   194 ms   159 ms  66.249.95.132
 11   285 ms   247 ms   246 ms  209.85.142.51
 12   288 ms   282 ms   283 ms  72.14.233.138
 13   271 ms   283 ms   274 ms  64.233.174.97
 14                          Request timed out.
 15   269 ms   273 ms   283 ms  pc-in-f106.1e100.net [74.125.28.106]

Trace complete.

Output :


                

Comments :