Tracert or Traceroute in Java, without calling the OS

3

I'm developing a web application that will test the servers and bring the result equal to a tracert of Windows or traceroute of Linux. I'm developing in Java and using the above commands as follows:

I identify the server and call:

Runtime.getRuntime().exec("tracert " + hostCanonicalName);

After the execution I get the String and I add a graph (Vis.js) with the path where the request passed.

I've already researched the web and found nothing in Java that does otherwise.

Is there a framework that does this? I read something about HttpCliente and did not get a satisfactory answer.

I do not want to use something directly related to the OS and I still can not understand the commands completely, because every IP that I testo it returns a different pattern.

    
asked by anonymous 24.11.2014 / 19:55

1 answer

4

I also searched and on the first page already appeared interesting results. I do not know if they solve what they want but they seem to be what they need:

Code:

import java.net.InetAddress;

public class Ping {
    public static void main(String[] args) {
        try {
            if (args.length != 1) {
                System.out.println("Usage: java Ping <hostname>");
                System.exit(-1);
            }
            String host = args[0];
            int timeout = 3000;
            boolean status = InetAddress.getByName(host).isReachable(timeout);
            System.out.println(host + ": reachable? " + status);
        } catch (java.net.UnknownHostException e) {
            e.printStackTrace();
        } catch (java.io.IOException ioe) 
            ioe.printStackTrace();
        }
    }
}

I placed GitHub for future reference .

ping is the basis of traceroute . From it it is possible to set up an algorithm to trace the route.

    
24.11.2014 / 20:24