views:

61

answers:

2

Hi All,

Is it possible to specify the IP address a WebRequest should use when creating a connection to a remote resource? For example, I have an MVC 2 website which runs on IP 0.0.0.10, but the server has 0.0.0.1 - 0.0.0.10 assigned to it. In the website there is a class that will be initialized based on user input and it will create requests to remote resources.

The problem I'm having is that the WebRequest is most likely using 0.0.0.1 as it is the first IP of the server instead of the IP of the website, thus causing requests to be blocked from remote resources that filter by IPs...

So, is there a way to specify the IP the WebRequest should use when performing the request. Alternativelly, it doesn't have to be a solution for WebRequest, it can be a solution for HttpWebRequest, or if need be something else. If I have to I will alter the code for the requests/responses.

Anyway, help would be much appreciated! Thanks in advance!

A: 

What you want to do is IP address spoofing - http://en.wikipedia.org/wiki/IP_address_spoofing.

You could make that filter consider the address range as valid. Is that an option?

Leniel Macaferi
Sort of, based on the Wiki article, if I spoof the packets, the responses from the remote resources will go to the spoofed packed IP. This would be a problem. Even if the class was spoofing its source IP with the real IP of the website, it still wouldn't get the response because the IP that really sent the request is still the server IP... I need the class to use a specified IP for the entire request cycle.
Alex
But it's not really spoofing, right? The server actually owns all of these addresses... Alex is just looking to indicate to the (Http)WebRequest that he wants a specific one, not the default.
JaredReisinger
+1  A: 

I think you want to use the HttpWebRequest.ServicePoint to specify a particular IP address to use for the request. See the MSDN doc, or better yet, Malar Chinnusamy's blog post that seems to be doing exactly what you're looking for.

JaredReisinger
This is what I wanted. Thing is, I figured out my issue with the remote resource (which I thought was doing IP filtering, and the solution was just stupid and pissed me off (and not because I was screwing up...)) during the process of updating the code. Right now both IP specific and non-specific calls work, so I can only assume that the delegate talked about in the Malar's blog works. Either way, I'm going to stick to the IP specific version just to be on the safe side. Thanks for the help!
Alex