美文网首页
[转]Android利用ping方式判定是否连接Internet

[转]Android利用ping方式判定是否连接Internet

作者: 扳手扳死你 | 来源:发表于2017-03-31 11:43 被阅读0次

public classPing {

public static final booleanping() {

String result =null;

try{

String ip ="www.baidu.com";//除非百度挂了,否则用这个应该没问题~

Process p = Runtime.getRuntime().exec("ping -c 2 -w 100 "+ ip);//ping3次

//读取ping的内容,可不加。

InputStream input = p.getInputStream();

BufferedReader in =newBufferedReader(newInputStreamReader(input));

StringBuffer stringBuffer =newStringBuffer();

String content ="";

while((content = in.readLine()) !=null) {

stringBuffer.append(content);

}

LogUtils.i("TTT","result content : "+ stringBuffer.toString());

// PING的状态

intstatus = p.waitFor();

if(status ==0) {

result ="successful~";

return true;

}else{

result ="failed~ cannot reach the IP address";

}

}catch(IOException e) {

result ="failed~ IOException";

}catch(InterruptedException e) {

result ="failed~ InterruptedException";

}finally{

LogUtils.i("TTT","result = "+ result);

}

return false;

}

相关文章

  • [转]Android利用ping方式判定是否连接Internet

    public classPing { public static final booleanping() { St...

  • Ping工具

    PING (Packet Internet Groper),因特网包探索器,用于测试网络连接量的程序。Ping发送...

  • 9-29ping

    PING (Packet Internet Groper),因特网包探索器,用于测试网络连接量的程序。Ping发送...

  • Python实现Ping程序

    Ping简介 PING (Packet Internet Groper),网络包探索器,用于测试网络连接量的程序 ...

  • 【干货】网络中常用的9个命令,超级实用

    1.ping 命令 PING (Packet Internet Groper),因特网包探索器,用于测试网络连接量...

  • 7.制作的ping库

    1.ping 是什么? ping(网络诊断工具),用于测试网络连接量的程序.利用ping命令可以检查网络的是否连通...

  • ping ,time,TTL详解

    一,什么是ping PING (Packet Internet Grope),因特网包探索器,用于测试网络连接量的...

  • PING

    PING命令(Packet Internet Grope) PING,因特网包探索器,用于测试网络连接量的程序。P...

  • Android 检测网络类型及是否能用

    Android 中网络连接检测和使用ping检测网络是否可访问Android:检测网络状态&监听网络变化 获得Co...

  • Android ping(packet internet gro

    最近接到一个需求:增加一项"网络监测"功能,需要进行对于域名的探测。 接下来对于基本命令的记录: 可以先在cmd中...

网友评论

      本文标题:[转]Android利用ping方式判定是否连接Internet

      本文链接:https://www.haomeiwen.com/subject/gwamottx.html