简体   繁体   English

Java:检查给定的ip和端口是否是代理服务器

[英]Java: check if given ip and port is proxy server

Is it posible in java to check if given ip with port is proxy server ? 在java中检查端口给定的ip是否为代理服务器是否可行?

I can check if given port is open using socket. 我可以使用套接字检查给定的端口是否打开。

Socket socket = new Socket();
socket.connect(new InetSocketAddress(ip, port), 5000);

How to check if it is a proxy server ? 如何检查它是否是代理服务器?

There is no direct way to detect if the IP address is behind a proxy because Proxies can be elective about whether or not they send the X-Forwarded-For header (which contains the originating IP). 由于代理可以选择是否发送X-Forwarded-For标头(包含原始IP),因此无法直接检测IP地址是否位于代理之后。

A proxy that doesn't send this header, or record the originating IP in logs, is said to be an "anonymizing" proxy. 不发送此标头或不将原始IP记录在日志中的代理称为“匿名”代理。 In the case you mention, the proxy you were using likely forwarded this header to the endpoint you were accessing, so your connection was not anonymized. 在您提到的情况下,您正在使用的代理可能将此标头转发到您正在访问的端点,因此您的连接未匿名。

There are multiple ways to detect whether or not your traffic is of proxy origin. 有多种方法可以检测您的流量是否来自代理。 Two easy ones are: 两个简单的是:

  • Presence of the X-Forwarded-For header (or custom data in forwarded headers) X-Forwarded-For标头(或转发标头中的自定义数据)的存在
  • Cross-checking known IPs of proxies or exit relays (TOR) 交叉检查代理或出口中继(TOR)的已知IP

There are other ways, possibly requiring additional intelligence on the server, perhaps to correlate requests across connections from different IPs, ie looking at user-agent criteria and timing of requests, cookies, LSOs in flash, (one of the reasons you'd want cookies and Flash player disabled to really anonymize yourself). 还有其他方法,可能需要服务器上的其他智能,也许需要将来自不同IP的连接之间的请求关联起来,即查看用户代理标准以及请求,cookie,闪存中的LSO的时间安排(您想要的原因之一) Cookie和Flash Player已被禁用,无法真正使自己匿名。

The only way is to connect to the IP/Port, send proxy requests to it, and see if it replies with proxy responses. 唯一的方法是连接到IP /端口,向它发送代理请求,然后查看它是否以代理响应进行回复。 This is because proxy protocols like SOCKS and HTTP (via the CONNECT verb) do not offer server-side greetings to let proxies identity themselves up front, the client sends the first packet in those protocols. 这是因为像SOCKS和HTTP这样的代理协议(通过CONNECT动词)不提供服务器端问候以使代理预先标识自己,客户端发送这些协议中的第一个数据包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM