简体   繁体   中英

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 ?

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).

A proxy that doesn't send this header, or record the originating IP in logs, is said to be an "anonymizing" proxy. 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)
  • Cross-checking known IPs of proxies or exit relays (TOR)

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).

The only way is to connect to the IP/Port, send proxy requests to it, and see if it replies with proxy responses. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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