码迷,mamicode.com
首页 > 移动开发 > 详细

android中ping命令的实现

时间:2015-03-17 14:17:13      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

/**
* 判断Ping 网址是否返回成功

* @param netAddress
* @return
*/
public static String isPingSuccess(int pingNum, String m_strForNetAddress) {
StringBuffer tv_PingInfo = new StringBuffer();
try {


Process p = Runtime.getRuntime().exec("/system/bin/ping -c " + pingNum + " " + m_strForNetAddress); // 10.83.50.111
// m_strForNetAddress
int status = p.waitFor();
String result ="";
if (status == 0) {
result = "success";
} else {
result = "failed";
}
String lost = new String();
String delay = new String();
BufferedReader buf = new BufferedReader(new InputStreamReader(p.getInputStream()));


String str = new String();
// 读出所有信息并显示
while ((str = buf.readLine()) != null) {
str = str + "\r\n";
tv_PingInfo.append(str);
}


return tv_PingInfo.toString();
} catch (Exception ex) {
ex.printStackTrace();
}
return "";
}

android中ping命令的实现

标签:

原文地址:http://blog.csdn.net/lsong89/article/details/44340375

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!