![maxmind country database maxmind country database](https://addons.prestashop.com/1319521-pbig/support-for-maxmind-geolite2-databases-mmdb.jpg)
Var fi = new FileInfo(“GeoLite2-Country.mmdb”)
#MAXMIND COUNTRY DATABASE CODE#
Var size = Convert.ToInt64((buffer, 0, 12).Trim(‘\0’), 8) įinally, the code to check the age is as follows Private static List ExtractTarEntries(Stream stream)
![maxmind country database maxmind country database](https://tyk.io/docs/img/2.10/geographic_dist.png)
The code to parse the TAR file is as follows Now, with a TAR stream, we have to separate this into a list of objects that define as follows Var gzip = new GZipStream(stream, CompressionMode.Decompress) So, we need to Gzip the file, and copy it into a memory stream – Which give’s us a Tar GZ file, Which is a file that is in Tar format (*Uncompressed, but a format where multiple files are stored as one) and Gzipped (Compressed). Var zippedStream = new MemoryStream(bData)
#MAXMIND COUNTRY DATABASE HOW TO#
Now, the next fun part is how to update this mmdb file automatically. Which should say that IP 8.8.8.8 is in the US (It’s Google) MaxMind DB (or MMDB) files facilitate the storage and retrieval of data in connection with IP addresses and IP address ranges, making queries for such data very fast and easy to perform. The database can be downloaded from sources like MaxMind. Var response = reader.Country(“8.8.8.8”) Ĭonsole.WriteLine() country for a given IP, you can upload an IP to a country mapping database (in CSV format). Var reader = new DatabaseReader(“GeoLite2-Country.mmdb”) On Elasticsearch Service deployments upload database using a custom bundle. These files must be uncompressed and use the respective -City.mmdb, -Country.mmdb, or -ASN.mmdb extensions. You can also use custom city, country, and ASN. Then download and unzip the GeoLite2-Country.mmdb file from and place it in your bin folder. mmdb database files from the MaxMind site. If you are happy with a rough lookup, then just pull the MaxMind Nuget package as follows So, if you don’t want to read further, and just jump to the code, here is the repo So, not only does this demo determine the Country from an IP address from an offline database, but it also has code to automatically download and update the data every month. You can donwload a free database from Maxmind that you can use to do the lookup offline, but it ads another complexity – that the fact that IP addresses change ownership, and can map to a different country, if you don’t keep the database updated. If you want to determine the country from an IP address, then there are a million and one APIs that you can use, but they tend to have free usage limits, plus there is a performance hit of making a network call every time.