title: Get IP address used by HttpWebRequest
body: <p>I am trying to reach a domain which is hosted over several IP's. When the IP range changes, our firewall will block any requests since the IP is not allowed.</p>
  
  <p>The app will notify us that it cannot establish a connection, but it does not tell us which IP address it was trying to use.  </p>
  
  <p>I am using a HTTPWebRequest to create the request, and a HttpWebResponse to receive the response</p>
  
  <p>It doesn't seem like the HttpWebRequest has the IP address in a property when instantiated with the URL, or after the request has been made. </p>
  
  <p>I am hesitant to see if I can get this from the HTTPWebResponse because I don't know if it will have an ip address if the firewall blocks it. </p>
  
  <p>One example that has been mentioned was to set a delegate to:</p>
  
  <pre><code>static void Main(string[] args)
          {
              HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.microsoft.com");
              req.ServicePoint.BindIPEndPointDelegate = new BindIPEndPoint(BindIPEndPoint1);
  
              Console.ReadKey();
          }
  
          public static IPEndPoint BindIPEndPoint1(ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount)
      {
          string IP = remoteEndPoint.ToString();
          return remoteEndPoint;
      }
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/6655713/how-to-get-ip-address-of-the-server-that-httpwebrequest-connected-to">How to get IP address of the server that HttpWebRequest connected to?</a></p>
  
  <p>This seemed to work, but I wanted to see if there was another way to do this without having to set a delegate. When I was debugging I noticed that this delegate was running constantly, and I don't know if that would be an issue or not. </p>