虽然迟到了,但我最近为 MaxMind GeoIP 数据库编写了一个 C++ API。我没有在 Windows 下测试它,我只在 Linux 下运行它,但它绝对不是 Linux 特定的。
我称之为 GeoLite2++。您可以在这里找到它: https: //www.ccoderun.ca/GeoLite2++/api/
Ubuntu 的源 tarball 和 .deb 文件位于: https ://www.ccoderun.ca/GeoLite2PP/download/?C=M;O=D
示例源代码:
#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;
Run Code Online (Sandbox Code Playgroud)
输出示例:
{
"city" :
{
"names" :
{
"de" : "Mountain View",
"en" : "Mountain View",
...
Run Code Online (Sandbox Code Playgroud)
它包括更多内容,例如获取单个字段与以 JSON 字符串形式抓取整个记录。
显示如何获取单个字段的示例:
GeoLite2PP::DB db("GeoLite2-City.mmdb");
std::string city = db.get_field( "65.44.217.6", "en",
GeoLite2PP::VCStr { "city", "names" } );
Run Code Online (Sandbox Code Playgroud)
中心类的描述如下: https ://www.ccoderun.ca/GeoLite2++/api/classGeoLite2PP_1_1DB.html
| 归档时间: |
|
| 查看次数: |
7884 次 |
| 最近记录: |