Implement Traceroute functionality in android

Music Blues picture Music Blues · Apr 4, 2013 · Viewed 10.2k times · Source

This is the first time I am asking any question so forgive me for my any mistake.

I want to implement traceroute functionality like this apps available in android play store.

Visual TracertPro

Traceroute

I know that when typing in CMD in windows traceroute google.com will display all intermediate IP used.

Now what I have tried.

I try using traceroute command but android not support traceroute only rooted device support it.

Process process =Runtime.getRuntime().exec("traceroute yahoo.com");
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);
reader.close();
Log.d("*************", ""+output);

So I thought to achieve using ping command but couldn't get any success.By using ping command it only gives ip of google.com not as I need and above apps display.

Process process = Runtime.getRuntime().exec("/system/bin/ping -t 1 -c 1 google.com");

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);
reader.close();
Log.d("*************", ""+output);

Please guide me how to achieve this. Some link or some tutorial will be very useful.

Thanking you in advance.

Answer

amccormack picture amccormack · Apr 4, 2013

The busybox utility includes traceroute. You can run busybox on your device without rooting your phone by following this youtube tutorial. You should then be able to use the first code segment you posted to query traceroute from within your app. Of course, you will need to make sure that you use the correct path when calling traceroute.