0

I am creating a Http proxy that seats between the web browser and the web server and based on my requirements the proxy server should get the IP address and port number of the web browser that has made a request. Here is a class that represent the connection between the proxy and web browser.

  public class Client
  {
    public Client(IPAddress browserIP, int browserPort)
    {
       /*Use browserIP and browserPort to create a socket object*/
    }
  }

Note that i am not using neither HttListener nor HttpRequest objects! I have created a custom Request object that allows me to set the http headers and other stuff that the HttpRequest object doesn't do;but my Request object doesn't have a method to get the browser IP address and Port.

4

2 回答 2

1

Check out this class

You can use the Request object to get the IP of the requesting end.

string remoteAddr = Request.UserHostAddress;

EDIT: That'll get you the Hostname. good enough to get started with!

于 2011-12-04T07:32:49.557 回答
1
  string  ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (ipaddress == "" || ipaddress == null)
                ipaddress = Request.ServerVariables["REMOTE_ADDR"];

Try the above. it fetches the ip of the requesting client.

于 2011-12-04T07:32:55.473 回答