GeoLite2++  v0.0.1-2711
C++ API for MaxMind's GeoLite2 Database
Looking for a senior C++ dev? I'm looking for work. Hire me!
Usage

Query the GeoLite2 database and return a JSON string with the details for the given address:

#include <GeoLite2PP.hpp>
...
GeoLite2PP::DB db( "/opt/stuff/GeoLite2-City.mmdb" );
std::string json_ = db.lookup( "216.58.216.163" );
std::cout << json << std::endl;

Query the GeoLite2 database and return very specific field values for the given address:

#include <GeoLite2PP.hpp>
...
GeoLite2PP::DB db( "/opt/stuff/GeoLite2-City.mmdb" );
std::string city = db.get_field( "216.58.216.163", GeoLite2PP::VCStr { "city" , "names" , "en" } );
std::string country = db.get_field( "216.58.216.163", GeoLite2PP::VCStr { "country" , "names" , "en" } );
std::string latitude = db.get_field( "216.58.216.163", GeoLite2PP::VCStr { "location", "latitude" } );

The fields in the vector (e.g., "city", "names", "en") are used to traverse the structures and return exact values. This traversal path can be determined by comparing against the .json output from the previous call, part of which is:

{
"city" :
{
"names" :
{
"de" : "Mountain View",
"en" : "Mountain View",
"fr" : "Mountain View",
"ja" : "マウンテンビュー",
"ru" : "Маунтин-Вью",
"zh-CN" : "芒廷维尤"
}
},

Calling db.get_field() with a vector containing "city", "names", "en" would return the English name for the given city, or "Mountain View" in this example.

For additional details and methods that can be called to query MaxMind's GeoLite2 IP address database, please refer to the documentation for GeoLite2PP::DB. For example:

API Description
GeoLite2PP::DB Class to talk to the GeoLite2 database.
GeoLite2PP::DB::DB() Constructor to gain access to the database.
GeoLite2PP::DB::lookup() Look up an IP address and return all the information as a JSON string.
GeoLite2PP::DB::get_all_fields() Look up an IP address and return a std::map of many fields.