1

I've been using the .NET WebClient class, but whenever I try to use the proxy settings (just specifying one of the IP addresses without any credentials here http://hidemyass.com/proxy-list/) the target server still thinks I'm on the normal IP address.

By "normal" I mean the static IP address provided by our ISP rather than the proxy IP.

WebClient wc = new WebClient();
wc.Proxy = new WebProxy("122.72.11.200");
Console.Write(wc.DownloadString("hostip.info"));

Am I missing something super-obvious?

MX D
  • 2,453
  • 4
  • 35
  • 47
Jamie
  • 143
  • 8

2 Answers2

0

Many (non-anonymous) proxies will send a header containing the original IP address in the request. See Getting the client IP address: REMOTE_ADDR, HTTP_X_FORWARDED_FOR, what else could be useful?

Perhaps hostip.info is using such a header to find out your IP address. You could check what headers are sent by the proxy by making a request to an HTTP echo service, e.g. http://scooterlabs.com/echo instead of http://hostip.info .

BTW: How do you conclude from the output (an html page?) that hostip.info is returning your 'normal' IP address. And shouldn't a full URI like http://www.hostip.info be passed as an argument to DownloadString() ?

Community
  • 1
  • 1
The Nail
  • 8,355
  • 2
  • 35
  • 48
0

You are probably seeing your own external IP because you are not giving a port. Internally the WebProxy(Address) calls the CreateProxyUri() function, to turn your Ip into an uri. This would mean that from here on out port 80 would be used to do the requests, while your proxy most likely required a different port (looking at the site you provided, this seems to be the case)

private static Uri CreateProxyUri(string address) {
    if (address == null) {
        return null;
    }
    if (address.IndexOf("://") == -1) {
        address = "http://" + address;
    }
    return new Uri(address);
}

You could fix it by calling the WebProxy(address, port) constructor instead with the proper port. Or by appending :port to the address string, where port depicts a port number.

MX D
  • 2,453
  • 4
  • 35
  • 47