title: Obtaining External IP with ASP.NET Core 2.1
body: <p>I am attempting to obtain similar information as found on <a href="https://www.whatismybrowser.com/" rel="nofollow noreferrer">https://www.whatismybrowser.com</a>. I specifically am looking for the external and local IP addresses. This is the .NET Core code that I am using to obtain this information:</p>
  
  <p><strong>HomeController.cs</strong></p>
  
  <pre><code>ViewData["RemoteIp"] = HttpContext.Connection.RemoteIpAddress.ToString();
  ViewData["LocalIp"] = HttpContext.Connection.LocalIpAddress.ToString();
  </code></pre>
  
  <p><strong>Startup.cs</strong></p>
  
  <pre><code>    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
      {
          app.UseForwardedHeaders(new ForwardedHeadersOptions
          {
              ForwardedHeaders = ForwardedHeaders.XForwardedFor
          });
  </code></pre>
  
  <p>The application lives behind an F5, so it results with a remote IP with my machine IP and a local IP that is the loopback IP address. The DNS entry is available externally, which then goes through the F5, then points to the server running the application.</p>
  
  <p>Ideally, I would like the remote IP to return the external IP as done in the <a href="https://www.ipify.org/" rel="nofollow noreferrer">ipify API</a>.</p>
  
  <p>I've reviewed the following SO threads already in attempt for a solution: <a href="https://stackoverflow.com/questions/51116403/how-to-get-client-ip-address-in-asp-net-core-2-1">How to get Client IP address in ASP.NET Core 2.1</a></p>
  
  <p>I've also reviewed the MSDN documentation as found here: <a href="https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-2.1" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-2.1</a></p>
  
  <p>One other factor: I plan on reusing this concept across multiple devices, including iOS, Android, and Windows platforms. I haven't decided on a framework, but I've entertained the ideas of Xamarin and PhoneGap.</p>