Giter Site home page Giter Site logo

ipdb-cplusplus's Introduction

ipdb-cplusplus

IPIP.net officially supported IP database ipdb format parsing library

Dependence

dnf install rapidjson-devel

Build & Run & Output

g++ -std=c++11 main.cpp ipdb.cpp -o main

./main

IPv4 Support: 0
IPv6 Support: 1
Build Time: 1535451865
Languages: CN EN 
...

Example

#include "ipdb.h"
#include <iostream>

int main() {
    try {
        auto db = std::make_shared<ipdb::City>("/root/cpp/ipdb-cplusplus/mydata6vipday4.ipdb");
        std::cout << "IPv4 Support: " << db->IsIPv4Support() << std::endl; // check database support ip type
        std::cout << "IPv6 Support: " << db->IsIPv6Support() << std::endl; // check database support ip type
        std::cout << "Build Time: " << db->BuildTime() << std::endl; // database build time
        std::cout << "Languages: "; // database support language
        for (const auto &i:db->Languages())
            std::cout << i << " ";
        std::cout << std::endl; // database support fields
        std::cout << "Fields: ";
        for (const auto &i:db->Fields())
            std::cout << i << " ";
        std::cout << std::endl;

        std::cout << db->FindInfo("2001:250:200::", "CN").str() << std::endl; // return CityInfo
        for (const auto &i:db->Find("1.1.1.1", "CN")) // return std::vector<std::string>
            std::cout << i << ", ";
        std::cout << std::endl;
        for (const auto &i:db->FindMap("118.28.8.8", "CN")) // return std::map<std::string, std::string>
            std::cout << i.first << ": " << i.second << ", ";
        std::cout << std::endl;
        std::cout << db->FindInfo("127.0.0.1", "CN").str() << std::endl; // return CityInfo

    } catch (const char *e) {
        std::cout << e << std::endl;
    }
    return 0;
}

ipdb-cplusplus's People

Contributors

ipipdotnet avatar originalimoc avatar yueeng avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.