检查Java中的代理匿名性



我需要确定代理匿名级别。我使用以下php脚本进行检测:

<?php
if (!getenv('HTTP_X_FORWARDED_FOR')){
    echo "Anonymous";
    exit;
}
if ((!getenv('HTTP_X_FORWARDED_FOR')) && (!getenv('HTTP_VIA')) && (!getenv('HTTP_PROXY_CONNECTION')){
    echo "High Anonymous";
    exit;
}
echo "Unknown";
?>

和我使用下一个代码页面加载(java):

private static String load(ProxyWrapper proxyWrapper, URL url) throws IOException {
        StringBuilder stringBuilder = new StringBuilder();
        SocketAddress socketAddress = null;
        try {
            socketAddress = new InetSocketAddress(proxyWrapper.getIp(), Integer.parseInt(proxyWrapper.getPort()));
        } catch (Exception e) {
            return null;
        }
        Proxy proxy = new Proxy(proxyWrapper.getType(), socketAddress);
        BufferedReader in = null;
        try {
            HttpURLConnection connection = (HttpURLConnection) url.openConnection(proxy);
            connection.setConnectTimeout(proxyWrapper.getTimeout());
            in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                stringBuilder.append(inputLine + "n");
            }
        } finally {
            if (in != null) {
                in.close();
            }
        }
        return stringBuilder.toString();
    }

我的问题是90%的工作匿名代理被脚本识别为"未知"。例如,如果我加载任何ip确定服务,它将显示代理的ip,这意味着它是匿名的。谁能告诉我出了什么问题?

你应该把你的echo "Unknown";放到else部分。否则将始终显示。

  <?php
    if (!getenv('HTTP_X_FORWARDED_FOR')){
        echo "Anonymous";
        exit;
    }elseif ((!getenv('HTTP_X_FORWARDED_FOR')) && (!getenv('HTTP_VIA')) && (!getenv('HTTP_PROXY_CONNECTION')){
        echo "High Anonymous";
        exit;
    } else {
    echo "Unknown";
}
    ?>

相关内容

  • 没有找到相关文章

最新更新