0

I'm trying to get the client(caller of web api) IP address in in my dotnet core web api. I'm getting the IP address as "::ffff:127.0.0.1" tested from different client networks. With localhost getting as ": ::1" I'm using the following code inside my action method :

var ipaddress = HttpContext.Features.Get<IHttpConnectionFeature>()?.RemoteIpAddress?.ToString();

Also tried with below code too:

var ipaddress  = Request.HttpContext.Connection.RemoteIpAddress;

Getting the same results. How can we fetch the exact IP address in dotnet core web api ?

Srikanth Reddy
  • 447
  • 1
  • 8
  • 23
  • Does this answer your question? [How do I get client IP address in ASP.NET CORE?](https://stackoverflow.com/questions/28664686/how-do-i-get-client-ip-address-in-asp-net-core) – Ian Kemp Dec 09 '20 at 11:05

1 Answers1

2

It looks like you're hosting your application on IIS, behind firewall, NAT, Apache routes, etc. Check the list of headers you're getting in the request. IP address might be one of them in case request have been forwarded. You may want to take a look on this answer as well: https://stackoverflow.com/a/62060533/9890829

Hirasawa Yui
  • 1,138
  • 11
  • 29