# Updating a contact's Location after Maxmind database download

**URL:** <https://forum.mautic.org/t/updating-a-contacts-location-after-maxmind-database-download/18894>\
**Category:** Product Support\
**Created:** [April 7, 2021, 9:01am UTC](https://forum.mautic.org/t/updating-a-contacts-location-after-maxmind-database-download/18894 "2021-04-07T09:01:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![pjrobertson](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/pjrobertson/32/2073_2.png) [@pjrobertson](https://forum.mautic.org/u/pjrobertson)\
**Post date:** [April 7, 2021, 9:01am UTC](https://forum.mautic.org/t/updating-a-contacts-location-after-maxmind-database-download/18894/1 "2021-04-07T09:01:17Z")

</div>

I realised my Maxmind database file wasn’t updating. After adding in my license key, I can now download the maxmind database file no problem. But I’m left wondering - is there a way to update the Location (country/city) of existing contacts in my system?

There doesn’t seem to be a cron method available for this. But I have over 8000 contacts with the city/country fields missing. Now maxmind is properly set up, I’d like to populate these fields.

Thanks

* * *

My Mautic version is: 3.2.4  
My PHP version is: v7.3.27  
My Database type and version is: Ver 15.1 Distrib 10.3.27-MariaDB

---

<div class="post-metadata">

**Author:** ![EJL](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ejl/32/12155_2.png) [@EJL](https://forum.mautic.org/u/EJL)\
**Post date:** [April 7, 2021, 4:59pm UTC](https://forum.mautic.org/t/updating-a-contacts-location-after-maxmind-database-download/18894/2 "2021-04-07T16:59:40Z")

</div>

Anonymous contacts I assume and not your identified contacts? I’m not aware of a way to retroactively update IP location.

---

<div class="post-metadata">

**Author:** ![pjrobertson](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/pjrobertson/32/2073_2.png) [@pjrobertson](https://forum.mautic.org/u/pjrobertson)\
**Post date:** [April 8, 2021, 1:59am UTC](https://forum.mautic.org/t/updating-a-contacts-location-after-maxmind-database-download/18894/3 "2021-04-08T01:59:27Z")

</div>

Thanks for the reply EJL.

I’m referring to identified contacts. Specifically, 1k+ contacts who’ve already submitted a ‘sign up for a newsletter’ form, with name +email.

---

<div class="post-metadata">

**Author:** ![sfahrenkrog1](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/sfahrenkrog1/32/4583_2.png) [@sfahrenkrog1](https://forum.mautic.org/u/sfahrenkrog1)\
**Post date:** [April 14, 2021, 8:27am UTC](https://forum.mautic.org/t/updating-a-contacts-location-after-maxmind-database-download/18894/4 "2021-04-14T08:27:33Z")

</div>

@pjrobertson Interesting problem!

I think there is no ready to run solution in mautic.

The geocoding for the ip address is only done during the page hit processing:

> <https://github.com/mautic/mautic/blob/7a2875bc16a6de50a1803fbc41b64278ae9b5428/app/bundles/PageBundle/Model/PageModel.php#L683>

The geocoding is only happening if you disabled ip anonymization (anonymize\_ip) and the geocoding details are persisted in the ip\_addresses Database Table (under ip\_details).

I got a similar problem last time and I used an external tool to geocode just the ip adresses to the countries and then imported the data back into the database.

(i used [Bulk IP address lookup | Batch IP checker | WhoisXML API](https://ip-geolocation.whoisxmlapi.com/bulk-gui) for the geocoding but there are others )

Or maybe you use a tool like this on github [GitHub - lexmartinez/ip-geocoder: Find geocoding information from IP address - Powered by ipapi.co](https://github.com/lexmartinez/ip-geocoder) and script your own solution.

Greetings  
Sebastian

---

<div class="post-metadata">

**Author:** ![pjrobertson](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/pjrobertson/32/2073_2.png) [@pjrobertson](https://forum.mautic.org/u/pjrobertson)\
**Post date:** [April 22, 2021, 4:13am UTC](https://forum.mautic.org/t/updating-a-contacts-location-after-maxmind-database-download/18894/5 "2021-04-22T04:13:22Z")

</div>

Thanks for the follow up @sfahrenkrog1 !

I just looked into the `ip_addresses` and `lead_ips_xref` tables. I thought I could use your script idea to replace the `ip_details` content in the `ip_addresses` table, but the majority of the IPs seem to be set at 127.0.0.1. Strange (I don’t have ‘IP anonymization’ set up):

```auto
MariaDB> select count(*) from ip_addresses where ip_details = "N;";
+----------+
| count(*) |
+----------+
| 7615 |
+----------+

MariaDB> select count(*) from ip_addresses where ip_details = "N;" and ip_address != "127.0.0.1";
+----------+
| count(*) |
+----------+
| 249 |
+----------+

```

So while I thought the initial problem was that my IP addresses weren’t getting geo-populated, it seems like a bigger issue is that a large majority of IPs are set to `127.0.0.1`. I thought it might be because of an nginx front end acting as reverse proxy ([see this](https://autoize.com/logging-client-ip-addresses-behind-a-proxy-with-docker/)) but I don’t think so (although I have changed servers in the past 6 months, and things appear to be working now).

---

<div class="post-metadata">

**Author:** ![sfahrenkrog1](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/sfahrenkrog1/32/4583_2.png) [@sfahrenkrog1](https://forum.mautic.org/u/sfahrenkrog1)\
**Post date:** [April 22, 2021, 10:32am UTC](https://forum.mautic.org/t/updating-a-contacts-location-after-maxmind-database-download/18894/6 "2021-04-22T10:32:19Z")

</div>

Do you use php fpm in your setup?

---

<div class="post-metadata">

**Author:** ![pjrobertson](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/pjrobertson/32/2073_2.png) [@pjrobertson](https://forum.mautic.org/u/pjrobertson)\
**Post date:** [April 30, 2021, 1:49am UTC](https://forum.mautic.org/t/updating-a-contacts-location-after-maxmind-database-download/18894/7 "2021-04-30T01:49:57Z")

</div>

Not using php-fpm. I’m using CGI/FastCGI. My first thought was that it was a proxy issue, but that doesn’t seem to be the case.

---

<div class="post-metadata">

**Author:** ![silavapi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/silavapi/32/7424_2.png) [@silavapi](https://forum.mautic.org/u/silavapi)\
**Post date:** [April 30, 2021, 8:48am UTC](https://forum.mautic.org/t/updating-a-contacts-location-after-maxmind-database-download/18894/8 "2021-04-30T08:48:33Z")

</div>

You will most likely need to pass through the original client IP address - also the case if you are using something like Cloudflare.

Maybe this could help: [Using the Forwarded header | NGINX](https://www.nginx.com/resources/wiki/start/topics/examples/forwarded/) ?
