我需要确定代理匿名的级别。我使用以下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%的工作匿名代理被脚本识别为&#34; Unknown&#34;。例如,如果我加载任何ip确定服务,它将显示代理的IP,这意味着它是匿名的。 谁能告诉我这是什么问题?
答案 0 :(得分: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";
}
?>