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;
}