How to get Unix timestamp while pinging in Android

  • Replies:0
Pinger
  • Forum posts: 1

Apr 28, 2016, 1:47:22 PM via Website

I have been able to perform rudimentary pings in android and have been able to get the result using Processes in android. My code is as follows

try {
String pingCmd = "ping -s 100 -c 10 " + host;
String pingResult = "";
Runtime r = Runtime.getRuntime();
Process p = r.exec(pingCmd);
BufferedReader in = new BufferedReader(new
InputStreamReader(p.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
text.setText(inputLine + "\n\n");
pingResult += inputLine;
text.setText(pingResult);
}
in.close();
}//try
catch (IOException e) {
System.out.println(e);
}
I am running the following command String pingCmd = "ping -s 100 -c 10 " + host;. I want to get the unix timestamp with each ping I have already tried the following and have not got any results with them:

String pingCmd = "ping -s 100 -c 10 " + host+ " -D";

String pingCmd = "ping -s 100 -c 10 " + host+ "| while read pong; do echo "$(date): $pong"; done";

String pingCmd = "ping -s 100 -c 10 " + host+ "| perl -nle 'print scalar(localtime), " ", $_'";

String pingCmd = "ping -s 100 -c 10 " + host+ "| xargs -L 1 -I '{}' date '+%+: {}'";

I don't get any error when I run these just no result in the textview. Please tell me how to get the unix timestamp with every ping

I expect my output to look something like this on each ping

[1461167279.090372] 108 bytes from ir1.fp.vip.ne1.yahoo.com (98.138.253.109): icmp_seq=1 ttl=51 time=335 ms

Reply