android中ping命令的实现
* 判断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 "";
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。