android 下测试网络的丢包率和延迟(转)

2019-08-05  本文已影响0人  是我拉叔

https://blog.csdn.net/wjqjssz/article/details/7559959

String lost = new String();

String delay = new String();

Process p = Runtime.getRuntime().exec("ping -c 4 " + "119.147.15.13");

BufferedReader buf = new BufferedReader(new InputStreamReader(p.getInputStream()));

String str = new String();

while((str=buf.readLine())!=null){

if(str.contains("packet loss")){

int i= str.indexOf("received");

int j= str.indexOf("%");

System.out.println("丢包率:"+str.substring(i+10, j+1));

// System.out.println("丢包率:"+str.substring(j-3, j+1));

lost = str.substring(i+10, j+1);

}

if(str.contains("avg")){

int i=str.indexOf("/", 20);

int j=str.indexOf(".", i);

System.out.println("延迟:"+str.substring(i+1, j));

delay =str.substring(i+1, j);

delay = delay+"ms";

}

}

---------------------

作者:wjqjssz

来源:CSDN

原文:https://blog.csdn.net/wjqjssz/article/details/7559959

版权声明:本文为博主原创文章,转载请附上博文链接!

上一篇下一篇

猜你喜欢

热点阅读