Curl工具类

/**
     * curl,获取解析所有时间
     *
     * @param domain 域
     * @param isIPV4 是否使用IPV4探测
     * @return {@link DetectResult}
     * @throws Exception 异常
     */// curl https://en.sge.com.cn -w {"httpCode":%{http_code},"timeTotal":%{time_total},"timeNameLookUp":%{time_namelookup},"timeAppConnect":%{time_appconnect},"timePreTransfer":%{time_pretransfer},"timeStartTransfer":%{time_starttransfer},"timeRedirect":%{time_redirect}} -o /dev/null  -m 5 -k --insecure -s
    public static DetectResult allParametersCheck(String domain, boolean isIPV4) throws Exception {
        String cmd;
        if (isIPV4) {
            cmd = "curl " +
                    domain +
                    " -w %{http_code}:%{time_total}:%{time_connect}:%{time_namelookup}:%{time_appconnect}:%{time_pretransfer}:%{time_starttransfer}:%{time_redirect}:%{size_download}:%{speed_download} " +
                    "-o /dev/null  -m 5 -k --insecure -s";
        } else {
            cmd = "curl -6 " +
                    domain +
                    " -w %{http_code}:%{time_total}:%{time_connect}:%{time_namelookup}:%{time_appconnect}:%{time_pretransfer}:%{time_starttransfer}:%{time_redirect}:%{size_download}:%{speed_download} " +
                    "-o /dev/null  -m 5 -k --insecure -s";
        }

        String result;
        if (ShellUtil.isLinux()) {
            result = ShellUtil.runShell(cmd);
        } else {
            result = RuntimeUtil.execForStr(cmd);
        }
        log.info("探测结果:" + result);
        String[] results = result.split(StrUtil.COLON);
        DetectResult detectResult = new DetectResult();
        detectResult.setHttpCode(results[0]);
        detectResult.setTimeTotal(Double.valueOf(results[1]));
        detectResult.setTimeConnect(Double.valueOf(results[2]));
        detectResult.setTimeNameLookUp(Double.valueOf(results[3]));
        detectResult.setTimeAppConnect(Double.valueOf(results[4]));
        detectResult.setTimePreTransfer(Double.valueOf(results[5]));
        detectResult.setTimeStartTransfer(Double.valueOf(results[6]));
        detectResult.setTimeRedirect(Double.valueOf(results[7]));
        detectResult.setSizeDownload(Double.valueOf(results[8]));
        detectResult.setSpeedDownload(Double.valueOf(results[9]));

        detectResult.setDomain(domain);
        log.info(StrUtil.toString(detectResult));
        return detectResult;
    }

你可能感兴趣的:(java,jvm)