Question

I have looked and looked and I can't seen to find a C++ version of GeoIP. I know there is a version of it in C, but I can't seem to get it working with Micosoft Visual Studio 2012 C++

I have tried:

So,

  1. Does a GeoIPC++ version exist?
  2. Is there another lib that does IP to country like GeoIP in C++?
  3. Is there a tutorial on how to get GeoIP working with C++?

Sorry for all the questions but i have looked and looked and I can't seem to find a solution.

Was it helpful?

Solution 2

GeoIP is an online database which is updating its data everyday (or monthly!).

Also, You can have a big offline database to map IP-to-Location beside your application (and you need keep it up to date periodically).

GeoIP is not bound to a specific programming language, you can connect to this database using a web-service mechanism. Simply connect to the online service by a TCP/HTTP request and retrieve data.

The HTTP API requires you to pass a set of parameters as an HTTP GET or POST. Results are returned in a simple text format documented below.

We offer several different services, each providing a different amount of information about the IP address.

OTHER TIPS

Late to the party, but I wrote a C++ API for the MaxMind GeoIP db recently. I didn't test it under Windows, I only ran it under Linux, but it definitely isn't Linux-specific.

I called it GeoLite2++. You can find it here: https://www.ccoderun.ca/GeoLite2++/api/

Source tarball and .deb files for Ubuntu are here: https://www.ccoderun.ca/GeoLite2PP/download/?C=M;O=D

Example source code:

#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;

Example output:

{
    "city" : 
    {
        "names" : 
        {
            "de" : "Mountain View",
            "en" : "Mountain View",
            ...

It includes more, such as getting individual fields versus grabbing entire records as JSON strings.

An example showing how to grab a single field:

GeoLite2PP::DB db("GeoLite2-City.mmdb");
std::string city = db.get_field( "65.44.217.6", "en",
    GeoLite2PP::VCStr { "city", "names" } );

The central class is described here: https://www.ccoderun.ca/GeoLite2++/api/classGeoLite2PP_1_1DB.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top