Sample code for 30+ languages & platforms
Unicode C

AbuseIPDB Check Endpoint

See more _Miscellaneous_ Examples

The check endpoint accepts a single IP address (v4 or v6). Optionally you may set the maxAgeInDays parameter to only return reports within the last x amount of days.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkHttpW.h>
#include <C_CkHttpRequestW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttpW http;
    HCkHttpRequestW req;
    HCkHttpResponseW resp;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *reportedAt;
    const wchar_t *comment;
    int reporterId;
    const wchar_t *reporterCountryCode;
    const wchar_t *reporterCountryName;
    int j;
    int count_j;
    int intVal;
    const wchar_t *dataIpAddress;
    BOOL dataIsPublic;
    int dataIpVersion;
    BOOL dataIsWhitelisted;
    int dataAbuseConfidenceScore;
    const wchar_t *dataCountryCode;
    const wchar_t *dataUsageType;
    const wchar_t *dataIsp;
    const wchar_t *dataDomain;
    const wchar_t *dataCountryName;
    int dataTotalReports;
    int dataNumDistinctUsers;
    const wchar_t *dataLastReportedAt;
    int i;
    int count_i;

    success = FALSE;

    //  This example assumes the Chilkat API to have been previously unlocked.
    //  See Global Unlock Sample for sample code.

    http = CkHttpW_Create();

    //  Implements the following CURL command:

    //  curl -G https://api.abuseipdb.com/api/v2/check \
    //    --data-urlencode "ipAddress=118.25.6.39" \
    //    -d maxAgeInDays=90 \
    //    -d verbose \
    //    -H "Key: $YOUR_API_KEY" \
    //    -H "Accept: application/json"

    //  Use the following online tool to generate HTTP code from a CURL command
    //  Convert a cURL Command to HTTP Source Code

    req = CkHttpRequestW_Create();
    CkHttpRequestW_putHttpVerb(req,L"GET");
    CkHttpRequestW_putPath(req,L"/api/v2/check");
    CkHttpRequestW_putContentType(req,L"application/x-www-form-urlencoded");
    CkHttpRequestW_AddParam(req,L"maxAgeInDays",L"90");
    CkHttpRequestW_AddParam(req,L"verbose",L"");
    CkHttpRequestW_AddParam(req,L"ipAddress",L"118.25.6.39");

    CkHttpRequestW_AddHeader(req,L"Key",L"$YOUR_API_KEY");
    CkHttpRequestW_AddHeader(req,L"Accept",L"application/json");

    resp = CkHttpResponseW_Create();
    success = CkHttpW_HttpSReq(http,L"api.abuseipdb.com",443,TRUE,req,resp);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkHttpRequestW_Dispose(req);
        CkHttpResponseW_Dispose(resp);
        return;
    }

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_Load(jResp,CkHttpResponseW_bodyStr(resp));
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonObjectW_emit(jResp));

    respStatusCode = CkHttpResponseW_getStatusCode(resp);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpResponseW_header(resp));
        wprintf(L"Failed.\n");
        CkHttpW_Dispose(http);
        CkHttpRequestW_Dispose(req);
        CkHttpResponseW_Dispose(resp);
        CkJsonObjectW_Dispose(jResp);
        return;
    }

    //  Sample JSON response:
    //  (Sample code for parsing the JSON response is shown below)

    //  {
    //    "data": {
    //      "ipAddress": "118.25.6.39",
    //      "isPublic": true,
    //      "ipVersion": 4,
    //      "isWhitelisted": false,
    //      "abuseConfidenceScore": 1,
    //      "countryCode": "CN",
    //      "usageType": "Data Center\/Web Hosting\/Transit",
    //      "isp": "Tencent Cloud Computing (Beijing) Co. Ltd",
    //      "domain": "tencent.com",
    //      "hostnames": [
    //      ],
    //      "countryName": "China",
    //      "totalReports": 2,
    //      "numDistinctUsers": 1,
    //      "lastReportedAt": "2021-04-03T18:55:00+00:00",
    //      "reports": [
    //        {
    //          "reportedAt": "2021-03-10T10:07:53+00:00",
    //          "comment": "SSH login attempts with user root.",
    //          "categories": [
    //            18,
    //            22
    //          ],
    //          "reporterId": 54484,
    //          "reporterCountryCode": "CN",
    //          "reporterCountryName": "China"
    //        },
    //        {
    //          "reportedAt": "2021-03-09T09:47:57+00:00",
    //          "comment": "SSH login attempts with user root.",
    //          "categories": [
    //            18,
    //            22
    //          ],
    //          "reporterId": 54484,
    //          "reporterCountryCode": "CN",
    //          "reporterCountryName": "China"
    //        }
    //      ]
    //    }
    //  }

    //  Sample code for parsing the JSON response...
    //  Use the following online tool to generate parsing code from sample JSON:
    //  Generate Parsing Code from JSON

    //  Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
    //  See this example explaining how this memory should be used: const char * functions.

    dataIpAddress = CkJsonObjectW_stringOf(jResp,L"data.ipAddress");
    dataIsPublic = CkJsonObjectW_BoolOf(jResp,L"data.isPublic");
    dataIpVersion = CkJsonObjectW_IntOf(jResp,L"data.ipVersion");
    dataIsWhitelisted = CkJsonObjectW_BoolOf(jResp,L"data.isWhitelisted");
    dataAbuseConfidenceScore = CkJsonObjectW_IntOf(jResp,L"data.abuseConfidenceScore");
    dataCountryCode = CkJsonObjectW_stringOf(jResp,L"data.countryCode");
    dataUsageType = CkJsonObjectW_stringOf(jResp,L"data.usageType");
    dataIsp = CkJsonObjectW_stringOf(jResp,L"data.isp");
    dataDomain = CkJsonObjectW_stringOf(jResp,L"data.domain");
    dataCountryName = CkJsonObjectW_stringOf(jResp,L"data.countryName");
    dataTotalReports = CkJsonObjectW_IntOf(jResp,L"data.totalReports");
    dataNumDistinctUsers = CkJsonObjectW_IntOf(jResp,L"data.numDistinctUsers");
    dataLastReportedAt = CkJsonObjectW_stringOf(jResp,L"data.lastReportedAt");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"data.hostnames");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"data.reports");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        reportedAt = CkJsonObjectW_stringOf(jResp,L"data.reports[i].reportedAt");
        comment = CkJsonObjectW_stringOf(jResp,L"data.reports[i].comment");
        reporterId = CkJsonObjectW_IntOf(jResp,L"data.reports[i].reporterId");
        reporterCountryCode = CkJsonObjectW_stringOf(jResp,L"data.reports[i].reporterCountryCode");
        reporterCountryName = CkJsonObjectW_stringOf(jResp,L"data.reports[i].reporterCountryName");
        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"data.reports[i].categories");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            intVal = CkJsonObjectW_IntOf(jResp,L"data.reports[i].categories[j]");
            j = j + 1;
        }

        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkHttpRequestW_Dispose(req);
    CkHttpResponseW_Dispose(resp);
    CkJsonObjectW_Dispose(jResp);

    }