android 丢包率的计算
2013-09-30 15:13:41 来源:WEB开发网核心提示:import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;public class ss {/** * @param args */public static void main(String[]
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class ss { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub // System.out.println(iplongToIp(999756777)); String lost = new String(); String delay = new String(); Process p = null; try { p = Runtime.getRuntime().exec("ping 192.168.146.55"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } BufferedReader buf = new BufferedReader(new InputStreamReader( p.getInputStream())); String str = new String(); try { while ((str = buf.readLine()) != null) { System.out.println(str); 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"; } } } catch (Exception e) { // TODO: handle exception } System.out.println(lost); } public static String iplongToIp(long ipaddress) { StringBuffer sb = new StringBuffer(""); sb.append(String.valueOf((ipaddress >>> 24))); sb.append("."); sb.append(String.valueOf((ipaddress & 0x00FFFFFF) >>> 16)); sb.append("."); sb.append(String.valueOf((ipaddress & 0x0000FFFF) >>> 8)); sb.append("."); sb.append(String.valueOf((ipaddress & 0x000000FF))); return sb.toString(); } }
- ››Android 当修改一些代码时,使用什么编译命令可以最...
- ››Android 如何添加一个apk使模拟器和真机都编译进去...
- ››Android 修改Camera拍照的默认保存路径
- ››Android 如何修改默认输入法
- ››android开发中finish()和System.exit(0)的区别
- ››Android手势识别简单封装类
- ››android中查看项目数字证书的两种方法
- ››Android中获取IMEI码的办法
- ››android 相机报错 setParameters failed
- ››Android重启运用程序的代码
- ››Android为ListView的Item设置不同的布局
- ››android bitmap与base64字符串的互相转换
赞助商链接