2

I am now developing an Android network diagnosis application (in Java) with my friends.

We've implemented the Ping function and now want to implement traceroute function using Ping, this is what happened in Windows cmd: Tracert in Windows

Then I tried to simulate the traceroute process by continuous Ping:Simulate traceroute by continuous Ping

To explain this, I am trying to simulate traceroute process by continuous Ping the same goal IP. Every time I increment ttl by 1 until reach the goal IP: Code in Android studio,record intermediate routers' IP address and then print out.

However on Android, I found the ICMP returned from intermediate did not contain their IP address info: Output in android studio.

Is there something wrong with the Ping command on Android or maybe it's the problem of the ICMP format? How can I get the IP address of the intermediate gateway? Is it possible to implement traceroute using Ping on Android? Appreciate if any suggestion.

This is 'Ping' part of our very primitive version:

    public String ping(String url) {
    String str = "";

    String tmp="";
    try {
        Process process = Runtime.getRuntime().exec(
                "ping -c 1 -t 1 " + url);
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                process.getInputStream()));
        int i;
        char[] buffer = new char[4096];
        StringBuffer output = new StringBuffer();
        while ((i = reader.read(buffer)) > 0) {
            output.append(buffer, 0, i);
            tmp=reader.readLine();
            System.out.println(tmp);

        }
        reader.close();

        // body.append(output.toString()+"\n");
        str = output.toString();
        // Log.d(TAG, str);
    } catch (IOException e) {
        // body.append("Error\n");
        e.printStackTrace();
    }
    return str;
}
Momomoom
  • 21
  • 2
  • Welcome Momomoom! Please consider putting code inline instead of doing screenshots, so we can understand and view it better :) – piraces Feb 22 '20 at 16:41
  • Sorry mate I can only provide limited part of our code – Momomoom Feb 22 '20 at 16:54
  • @Momomoom trying to do the same thing, let me know if you found a way! very interested. I'll keep looking and report back if i find anything. – Darkhydro Feb 03 '21 at 22:30

0 Answers0