android中ping命令的实现
Posted wzjhoutai
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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命令的实现的主要内容,如果未能解决你的问题,请参考以下文章
计算机网络实验(思科模拟器Cisco Packet Tracer)——查阅本机的网络配置与网络PING命令实现