0

Yesterday, I've got mail, announcing tiny amazon EC2 instances being able to have up to 8 IP addresses.

Let's say, I'm running an application on one of the instances. I'm using httpwebrequest to access websites. How do I control, which IP the request goes from?

Arsen Zahray
  • 24,367
  • 48
  • 131
  • 224
  • ok. Got my answer from here. Thanks everybody: http://stackoverflow.com/questions/3345387/how-to-change-originating-ip-in-httpwebrequest – Arsen Zahray Jul 08 '12 at 15:37

1 Answers1

2

Taken from this question

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://stackoverflow.com");

req.ServicePoint.BindIPEndPointDelegate = delegate(
ServicePoint servicePoint,
IPEndPoint remoteEndPoint,
int retryCount) {

if (remoteEndPoint.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6) {
    return new IPEndPoint(IPAddress.IPv6Any, 0);
} else {
    return new IPEndPoint(IPAddress.Any, 0);
}

};

Console.WriteLine(req.GetResponse().ResponseUri);
Community
  • 1
  • 1
John Mitchell
  • 9,653
  • 9
  • 57
  • 91