美文网首页
Android执行curl命令获取dns解析时间

Android执行curl命令获取dns解析时间

作者: lichao666 | 来源:发表于2022-01-21 15:17 被阅读0次

    参考链接:
    https://www.cnblogs.com/weiyiming007/p/10675053.html
    https://www.jianshu.com/p/40f698157330

    获取dns解析时间

    和linux中一样,使用curl命令可以获取dns解析时间,命令如下

    curl -o /dev/null -s -w %{time_namelookup}  http://www.baidu.com
    

    Android中执行linux命令,代码如下:

    String getdnstime(){
            Runtime mRuntime = Runtime.getRuntime();
            try {
                //Process中封装了返回的结果和执行错误的结果
                Process mProcess = mRuntime.exec("curl -o /dev/null -s -w %{time_namelookup}  http://www.baidu.com");
                BufferedReader mReader = new BufferedReader(new InputStreamReader(mProcess.getInputStream()));
                StringBuffer mRespBuff = new StringBuffer();
                char[] buff = new char[1024];
                int ch = 0;
                while ((ch = mReader.read(buff)) != -1) {
                    mRespBuff.append(buff, 0, ch);
                }
                mReader.close();
                return mRespBuff.toString();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return "";
        }
    

    相关文章

      网友评论

          本文标题:Android执行curl命令获取dns解析时间

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