Client IP Address Lookup not correct

Tony Feltham asked on March 20, 2018 14:21

I am trying to retrieve the IP of the user logging in so that I can log and track IP usage.

Using suggestions gleaned from posts I have tried to use the below with little joy.

If I attempt a login where my IP address is 86.174.74.88 RequestContext.UserHostAddress returns me 10.100.2.165 and the GeoIPHelper (see below) returns no values for any of the vars

GeoLocation currentGeoLocation = GeoIPHelper.GetCurrentGeoLocation(); if (currentGeoLocation != null) { var countryAndState = ValidationHelper.GetString(currentGeoLocation.CountryName, ""); var ipCountryCode = ValidationHelper.GetString(currentGeoLocation.CountryCode, ""); var ipRegion = ValidationHelper.GetString(currentGeoLocation.RegionName, ""); var ipCity = ValidationHelper.GetString(currentGeoLocation.City, ""); }

I have also looked into the Kentico event log which stores the IP address on Authentication (which I assume is core Kentico functionality) and it appears that this is not actually outputting the correct IP Address.

My IP Address is 86.174.74.88 and when I view event logs after logging in it states my IP address was 10.100.2.165

the 86. ip has correct GeoLocation data (using https://www.ip2location.com) the 10. IP has no GeoLocation data which explains the above.

If I chose to enter my IP Address as a BannedIP I assume I would therefore still be able to login as the perceived IP is 10.100.2.165 rather than 86.174.74.88

Have I understood this correctly and if not please can anyone explain what is occurring here and why Kentico is not registering the correct IP address.

Many Thanks

Recent Answers


Brenden Kehren answered on March 20, 2018 16:33

This all depends on where your site is running and how you access it. For instance, if you have a local instance running on an internal network, it will get your internal network IP address, hence it returning a 10.100 address. If you have an external site on a DMZ outside your firewall and if you access it internally it typically proceeds out through the firewall and accesses your domain, this returning your public facing IP address.

I'd get a better feel for how your network is setup then come report that and we can troubleshoot more from there.

1 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on March 21, 2018 00:37

You may be behind a proxy, check the header values of the request for a "x-forwarded" that will contain the original IP, along with what Brenden said.

Also know that in general, not every IP address will be locatable, it's always a little hit or miss

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.