首页 > 代码库 > android中ping命令的实现
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 "";
}
* 推断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命令的实现
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。