【发布时间】:2023-11-25 03:35:01
【问题描述】:
我已经能够在 android 中执行基本的 ping,并且已经能够使用 android 中的 Processes 获得结果。我的代码如下
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);
}
我正在运行以下命令String pingCmd = "ping -s 100 -c 10 " + host;。我想获得每个 ping 的 unix 时间戳,我已经尝试了以下方法,但没有得到任何结果:
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 '+%+: {}'";
当我在文本视图中运行这些只是没有结果时,我没有收到任何错误。请告诉我如何在每次 ping 时获取 unix 时间戳
我希望我的输出在每次 ping 时看起来像这样
[1461167279.090372] 108 bytes from ir1.fp.vip.ne1.yahoo.com (98.138.253.109): icmp_seq=1 ttl=51 time=335 ms
【问题讨论】:
标签: android linux unix ping unix-timestamp