Skip to content

Joungkyun/libkrisp

Repository files navigation

libkrisp - Korea ISP library

libkrispAPNIC에서 KRNIC(KISA)에 할당한 IP와 KRNIC에서 관리 대행자(ISP등) 및 독립 사용자에게 할당한 정보를 관리하는 library 입니다. 현재 IPv4 만 제공 하고 있습니다!!

이 library를 이용하여 한국에 할당된 IP에 대한 다음의 정보를 얻을 수 있습니다.

[root@host ~]$ krisplookup kisa.or.kr
kisa.or.kr (1.201.101.120): 주식회사 케이아이엔엑스 (KINXINC)
SUBNET    : 255.255.0.0
NETWORK   : 1.201.0.0
BROADCAST : 1.201.255.255
DB RANGE  : 1.201.0.0 - 1.201.255.255
NATION    : Korea, Republic of (KR)
[root@host ~]$

libkrisp 에서 공식적으로 제공을 하는 database는 다음 KISA에서 공개한 데이터 베이스를 기본 database로 사용을 합니다.

libkrisp 는 2개의 외부 database를 이용 합니다. 기본 database로는 다음 KISA에서 공개한 데이터 베이스를 기본 database로 사용을 합니다.

또 하나는, KISA에서 제공하는 database와 MaxMind에서 제공하는 GeoIP Lite database를 merge한 database를 제공 합니다.

기본 제공 되는 KISA database는 한국의 IP 및 ISP 정보만을 가지고 있어 빠르게 탐색할 수 있는 장점이 있지만 외국의 IP 대역에 대해서는 처리를 하지 못하기 때문에, 별도로 geoip lite를 merge 하여 외국의 IP 정보를 관리하도록 합니다. (단 외국 IP의 경우 ISP 정보는 가지고 있지 않습니다.)

libkrisp 의 database는 다음 URL에서 2006년 부터 현재까지의 database가 매월 1회씩 배포되고 있습니다.

database 갱신 문서를 참조 하십시오.

또한, MaxMind의 GeoIP 또는 GeoIPISP 상용 데이터를 구매를 하여 libkrisp database에 merge를 할 수 있으며, CSV format 을 잘 맞추면 임의의 데이터를 구성하여 사용할 수도 있습니다. 이에 관해서는 User deinfe database tool 문서를 참고 하십시오.

Requirements

API Usage

간단한 사용법은 아래와 같습니다. API 사용법에 대해서는 man page 또는 wiki page를 참조 하십시오.

#include <krisp.h>

int main (void) {
    KR_API * db;
    KRNET_API isp;
    //char * ip = "168.126.63.1";
    char * ip = "kns.kornet.net";
    int r;
    char * database = NULL;
    char err[1024];

    if ( kr_open (&db, database, err)) == false ) {
        fprintf (stderr, "ERROR Connect: %s\n", err);
        return 1;
    }

    // Check database modification. If libkrisp detects database
    // modification, reopen database. Default is 0 seconds (Don't check).
    // support libkrisp >= 3.1
    db->db_time_stamp_interval = 3600; // 1h
    
    isp.verbose = false;
    // defined SAFECPY_256 in krispapi.h
    SAFECPY_256 (isp.ip, addr);
    if ( kr_search (&isp, db) ) {
        printf ("ERROR: %s\n", isp.err);
        kr_close (&db);
        return 1;
    }

    kr_close (&db);
    
    printf ("%-15s %-15s %-20s", ip, isp.ip, isp.icode);
    // long2ip_r is include libipcalc.
    {
        char ip[16] = { 0, };
        printf ("%-15s ", long2ip_r (isp.start, ip));
        printf ("%-15s %s", long2ip_r (isp.end, ip), isp.iname);
    }
    
    return 0;
}

Related sub project

License

Copyright © 2016 JoungKyun.Kim all rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by the Free Software Foundation; either version 2 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU LESSER GENERAL PUBLIC LICENSE for more details.

You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.