0

我需要确定代理匿名级别。我使用以下 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,这意味着它是匿名的。谁能告诉我有什么问题?

4

1 回答 1

0

你应该把你的echo "Unknown";放到其他部分。否则总是显示。

  <?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";
}
    ?>
于 2015-12-23T20:58:40.753 回答