0
votes

In my .net core 5 api I need to get the remote IP from request. It works fine on my test server. Checked it several times from different networks.

BUT

on my client's server, I'm getting the same IP address regardless from where I'm calling the API. So, my problem is that on my server everything works fine, but on client's server, I'm getting false IP address.

I've installed the .Net 5 SDK I've compared it to my server and IIS (different versions of IIS, but configuration seems fine)

Any ideas?

2
Find the network administrators and discuss with them. You cannot merely get remote IP address from the request itself, as that IP address can be of a reverse proxy or anything in between, and the actual client IP address might appear in an HTTP header. - Lex Li
Check the x-forwarded-for header before, if that has a value, then use it. Assuming your proxy server is filling in that value correctly. - DavidG
Could you please post how you are getting the Remote IP? - Charlino
Have you tried calling that API direct from those different devices. - Jay
@Charlino Few months ago it didn't worked, but I assume recently there was some change and now its as simple as this: protected IPAddress RemoteIpAddress => HttpContext.Connection.RemoteIpAddress; - RoyM

2 Answers

0
votes

I will assume that you have LB environment. SO most probably you getting the LB IP. If this is the case. you should configure the LB to allow HTTP header transfer to the internal requests. Especially if you use internal HTTP direction across the DMZ. mainly you can rely on "x-forwarded-for" and the proxy server (LB) will fill that in and pass it to your internal servers.

0
votes

After talking to my client, apparently he knew that the server is in fact behind NAT (asked him about that before and he denied it🤷‍♂️)