Developer stories: IP databases

Time for a developer story.

Background

A little background: We are maintaining a pretty complex system which has a couple of stores attached for different countries and languages. Because it is Magento 1 it is slowly phased out and one of the remaining countries is Ireland.

One of the features is, that we are sending emails to the customer based on their geo ip instead of language, country or something else.

Bug report

Today I got a bug report, that one of their customers got an order confirmation with the “phase out” banner at the top, although Ireland still works on the system and isn’t phased out yet and there is no plan to change that. We were pretty nervous, because when we introduced the feature we already made a mistake and not only send the phase out banner to the US customers but to ALL english speaking customers. And doing this again would be pretty embarrassing for us.

So I immediately went bug hunting.

Bug description: Customer bought from Ireland but got the phase out banner.

  1. I checked the template for Ireland and it was (as hoped and expected) correct – no phase out banner.
  2. I checked the configuration for Ireland – just to be sure, that the template which is correct is used for order confirmation emails. Fine as well.
  3. Maybe the customer bought something for an Irish company but was not in Ireland – remember, the email sent is based on the GeoIP. But no, the address is in Ireland and while checking the IP address which is saved in Magento the online tool told me: Irish IP.

BUT! IPs are out and constantly sold

Thankfully we have a wide knowledge about this “internet” thing, although we try to concentrate on the things we know really well: ecommerce with Shopware, Magento and if needed and forced Shopify.

But one of the things in the internet, which are “lately” (as in the last 10(?) years) common is, that the IPv4 addresses are virtually out and therefore the buying and selling of small chunks of IP ranges are a daily business. And that means, that databases which tell you which IP range belongs to which country can be outdated very fast.

With this knowledge I checked the resolution of our application for IP to country and thankfully the GeoLite2-Country.mmdb file was part of the database. So i hacked a little script to check the IP of the order against this old database and who would have guessed, the database thinks the IP is from the US.

array(3) {
["continent"]=>
array(3) {
["code"]=>
string(2) "NA"
["geoname_id"]=>
int(6255149)
["names"]=>
array(8) {
["de"]=>
string(11) "Nordamerika"
["en"]=>
string(13) "North America"
["es"]=>
string(13) "Norteamérica"
["fr"]=>
string(17) "Amérique du Nord"
["ja"]=>
string(15) "北アメリカ"
["pt-BR"]=>
string(17) "América do Norte"
["ru"]=>
string(31) "Северная Америка"
["zh-CN"]=>
string(9) "北美洲"
}
}
["country"]=>
array(3) {
["geoname_id"]=>
int(6252001)
["iso_code"]=>
string(2) "US"
["names"]=>
array(8) {
["de"]=>
string(3) "USA"
["en"]=>
string(13) "United States"
["es"]=>
string(14) "Estados Unidos"
["fr"]=>
string(11) "États-Unis"
["ja"]=>
string(21) "アメリカ合衆国"
["pt-BR"]=>
string(14) "Estados Unidos"
["ru"]=>
string(6) "США"
["zh-CN"]=>
string(6) "美国"
}
}
["registered_country"]=>
array(3) {
["geoname_id"]=>
int(6252001)
["iso_code"]=>
string(2) "US"
["names"]=>
array(8) {
["de"]=>
string(3) "USA"
["en"]=>
string(13) "United States"
["es"]=>
string(14) "Estados Unidos"
["fr"]=>
string(11) "États-Unis"
["ja"]=>
string(21) "アメリカ合衆国"
["pt-BR"]=>
string(14) "Estados Unidos"
["ru"]=>
string(6) "США"
["zh-CN"]=>
string(6) "美国"
}
}
}

Keep your IP databases updated

That took me over an hour to find. Make sure you keep your IP databases updated.

And another tip: The same is true for timezones! 😜

One thought on “Developer stories: IP databases

Leave a Reply

Discover more from Winkelwagen

Subscribe now to keep reading and get access to the full archive.

Continue reading