资源简介

准确率99.9%的ip地址定位库,0.0x毫秒级查询,数据库文件大小只有1.5M,提供了java,php,c,python,nodejs,golang,c#查询绑定和Binary,B树,内存三种查询算法,妈妈再也不用担心我的ip地址定位!

资源截图

代码片段和文件信息

/**
 * default ip2region implementation
 *
 * @see        #ip2region.h
 * @author    chenxin
 * @date    2015-10-30
*/

#include “ip2region.h“
#include 
#include 

/**
 * create a new ip2region object
 *
 * @param    dbFile path
*/
IP2R_API uint_t ip2region_create(ip2region_t ip2rObj char *dbFile)
{
    memset(ip2rObj 0x00 sizeof(ip2region_entry));
    ip2rObj->headerLen = 0;
    ip2rObj->HeaderSip = (uint_t *) IP2R_MALLOC(TOTAL_HEADER_LENGTH);
    if ( ip2rObj->HeaderSip == NULL ) {
        return 0;
    }

    ip2rObj->HeaderPtr = (uint_t *) IP2R_MALLOC(TOTAL_HEADER_LENGTH);
    if ( ip2rObj->HeaderPtr == NULL ) {
        IP2R_FREE(ip2rObj->HeaderSip);
        return 0;
    }

    //open the db file
    ip2rObj->dbHandler = fopen(dbFile “rb“);
    if ( ip2rObj->dbHandler == NULL  ) {
        IP2R_FREE(ip2rObj->HeaderSip);
        IP2R_FREE(ip2rObj->HeaderPtr);
        //fprintf(stderr “Fail to open the db file %s\n“ ip2rObj>dbFile);
        //exit(-1);
        return 0;
    }

    ip2rObj->firstIndexPtr = 0;
    ip2rObj->lastIndexPtr  = 0;
    ip2rObj->totalBlocks   = 0;
    ip2rObj->dbBinStr      = NULL;

    return 1;
}

/**
 * destroy the specifield ip2region object
 *
 * @param    ip2region_t
*/
IP2R_API uint_t ip2region_destroy(ip2region_t ip2rObj)
{
    IP2R_FREE(ip2rObj->HeaderSip);
    ip2rObj->HeaderSip = NULL;
    IP2R_FREE(ip2rObj->HeaderPtr);
    ip2rObj->HeaderPtr = NULL;

    //close the db file resource
    if ( ip2rObj->dbHandler != NULL ) {
        fclose(ip2rObj->dbHandler);
        ip2rObj->dbHandler = NULL;
    }

    //free the db binary string
    if ( ip2rObj->dbBinStr != NULL ) {
        IP2R_FREE(ip2rObj->dbBinStr);
        ip2rObj->dbBinStr = NULL;
    }

    return 1;
}

/**
 * get the region associated with the specified ip address with the memory binary search algorithm
 *
 * @param   ip2rObj
 * @param   ip
 * @param   datablock
*/
IP2R_API uint_t ip2region_memory_search(ip2region_t ip2rObj uint_t ip datablock_t datablock) 
{
    int l h m p;
    uint_t sip eip dptr;
    int dataLen dataptr;
    long filesize;
    char *buffer;

    if ( ip2rObj->dbBinStr == NULL ) {
        //get the size of the file
        fseek(ip2rObj->dbHandler 0 SEEK_END);
        filesize = ftell(ip2rObj->dbHandler);
        fseek(ip2rObj->dbHandler 0 SEEK_SET);

        //alloc the buffer size
        ip2rObj->dbBinStr = IP2R_MALLOC(filesize);
        if ( ip2rObj->dbBinStr == NULL ) {
            return 0;
        }

        //now read the whole file
        if ( fread(ip2rObj->dbBinStr filesize 1 ip2rObj->dbHandler) != 1 ) {
            return 0;
        }

        buffer = ip2rObj->dbBinStr;
        ip2rObj->firstIndexPtr = getUnsignedInt(buffer 0);
        ip2rObj->lastIndexPtr  = getUnsignedInt(buffer 4);
        ip2rObj->totalBlocks   = (ip2rObj->lastIndexPtr-ip2rObj->firstIndexPtr)/INDEX_BLOCK_LENGTH + 1;
    }

    l = 0; h = ip2rObj->totalBlocks; dptr = 0;
    while

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-07-03 12:04  ip2region-master\
     文件         341  2018-07-03 12:04  ip2region-master\.gitignore
     文件        2264  2018-07-03 12:04  ip2region-master\CHANGES.md
     文件          63  2018-07-03 12:04  ip2region-master\Cargo.toml
     文件       12640  2018-07-03 12:04  ip2region-master\LICENSE.md
     文件        4665  2018-07-03 12:04  ip2region-master\README.md
     目录           0  2018-07-03 12:04  ip2region-master\binding\
     目录           0  2018-07-03 12:04  ip2region-master\binding\c#\
     目录           0  2018-07-03 12:04  ip2region-master\binding\c#\IP2Region\
     文件       13380  2018-07-03 12:04  ip2region-master\binding\c#\IP2Region\DBSearcher.cs
     文件        1899  2018-07-03 12:04  ip2region-master\binding\c#\IP2Region\DataBlock.cs
     文件        1639  2018-07-03 12:04  ip2region-master\binding\c#\IP2Region\DbConfig.cs
     文件         406  2018-07-03 12:04  ip2region-master\binding\c#\IP2Region\DbMakerConfigException.cs
     文件        1552  2018-07-03 12:04  ip2region-master\binding\c#\IP2Region\HeaderBlock.cs
     文件         987  2018-07-03 12:04  ip2region-master\binding\c#\IP2Region\IP2Region.csproj
     文件        2527  2018-07-03 12:04  ip2region-master\binding\c#\IP2Region\IndexBlock.cs
     文件        4405  2018-07-03 12:04  ip2region-master\binding\c#\IP2Region\Util.cs
     目录           0  2018-07-03 12:04  ip2region-master\binding\c#\IP2Region_ConsoleTest\
     目录           0  2018-07-03 12:04  ip2region-master\binding\c#\IP2Region_ConsoleTest\DBFile\
     文件     2724501  2018-07-03 12:04  ip2region-master\binding\c#\IP2Region_ConsoleTest\DBFile\ip2region.db
     文件         646  2018-07-03 12:04  ip2region-master\binding\c#\IP2Region_ConsoleTest\IP2Region_ConsoleTest.csproj
     文件        1869  2018-07-03 12:04  ip2region-master\binding\c#\IP2Region_ConsoleTest\Program.cs
     目录           0  2018-07-03 12:04  ip2region-master\binding\c#\IP2Region_ConsoleTest\Properties\
     目录           0  2018-07-03 12:04  ip2region-master\binding\c#\IP2Region_ConsoleTest\Properties\PublishProfiles\
     文件         627  2018-07-03 12:04  ip2region-master\binding\c#\IP2Region_ConsoleTest\Properties\PublishProfiles\FolderProfile.pubxml
     文件         389  2018-07-03 12:04  ip2region-master\binding\c#\IP2Region_ConsoleTest\Properties\PublishProfiles\FolderProfile.pubxml.user
     目录           0  2018-07-03 12:04  ip2region-master\binding\c\
     文件         506  2018-07-03 12:04  ip2region-master\binding\c\Makefile
     文件       11363  2018-07-03 12:04  ip2region-master\binding\c\ip2region.c
     文件        3484  2018-07-03 12:04  ip2region-master\binding\c\ip2region.h
     文件        2644  2018-07-03 12:04  ip2region-master\binding\c\testSearcher.c
............此处省略97个文件信息

评论

共有 条评论