Sample code for 30+ languages & platforms
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 C Downloads

C
#include <C_CkHttp.h>
#include <C_CkHttpRequest.h>
#include <C_CkHttpResponse.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttp http;
    HCkHttpRequest req;
    HCkHttpResponse resp;
    HCkJsonObject jResp;
    int respStatusCode;
    const char *reportedAt;
    const char *comment;
    int reporterId;
    const char *reporterCountryCode;
    const char *reporterCountryName;
    int j;
    int count_j;
    int intVal;
    const char *dataIpAddress;
    BOOL dataIsPublic;
    int dataIpVersion;
    BOOL dataIsWhitelisted;
    int dataAbuseConfidenceScore;
    const char *dataCountryCode;
    const char *dataUsageType;
    const char *dataIsp;
    const char *dataDomain;
    const char *dataCountryName;
    int dataTotalReports;
    int dataNumDistinctUsers;
    const char *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 = CkHttp_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 = CkHttpRequest_Create();
    CkHttpRequest_putHttpVerb(req,"GET");
    CkHttpRequest_putPath(req,"/api/v2/check");
    CkHttpRequest_putContentType(req,"application/x-www-form-urlencoded");
    CkHttpRequest_AddParam(req,"maxAgeInDays","90");
    CkHttpRequest_AddParam(req,"verbose","");
    CkHttpRequest_AddParam(req,"ipAddress","118.25.6.39");

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

    resp = CkHttpResponse_Create();
    success = CkHttp_HttpSReq(http,"api.abuseipdb.com",443,TRUE,req,resp);
    if (success == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkHttpRequest_Dispose(req);
        CkHttpResponse_Dispose(resp);
        return;
    }

    jResp = CkJsonObject_Create();
    CkJsonObject_Load(jResp,CkHttpResponse_bodyStr(resp));
    CkJsonObject_putEmitCompact(jResp,FALSE);

    printf("Response Body:\n");
    printf("%s\n",CkJsonObject_emit(jResp));

    respStatusCode = CkHttpResponse_getStatusCode(resp);
    printf("Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        printf("Response Header:\n");
        printf("%s\n",CkHttpResponse_header(resp));
        printf("Failed.\n");
        CkHttp_Dispose(http);
        CkHttpRequest_Dispose(req);
        CkHttpResponse_Dispose(resp);
        CkJsonObject_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 = CkJsonObject_stringOf(jResp,"data.ipAddress");
    dataIsPublic = CkJsonObject_BoolOf(jResp,"data.isPublic");
    dataIpVersion = CkJsonObject_IntOf(jResp,"data.ipVersion");
    dataIsWhitelisted = CkJsonObject_BoolOf(jResp,"data.isWhitelisted");
    dataAbuseConfidenceScore = CkJsonObject_IntOf(jResp,"data.abuseConfidenceScore");
    dataCountryCode = CkJsonObject_stringOf(jResp,"data.countryCode");
    dataUsageType = CkJsonObject_stringOf(jResp,"data.usageType");
    dataIsp = CkJsonObject_stringOf(jResp,"data.isp");
    dataDomain = CkJsonObject_stringOf(jResp,"data.domain");
    dataCountryName = CkJsonObject_stringOf(jResp,"data.countryName");
    dataTotalReports = CkJsonObject_IntOf(jResp,"data.totalReports");
    dataNumDistinctUsers = CkJsonObject_IntOf(jResp,"data.numDistinctUsers");
    dataLastReportedAt = CkJsonObject_stringOf(jResp,"data.lastReportedAt");
    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"data.hostnames");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"data.reports");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        reportedAt = CkJsonObject_stringOf(jResp,"data.reports[i].reportedAt");
        comment = CkJsonObject_stringOf(jResp,"data.reports[i].comment");
        reporterId = CkJsonObject_IntOf(jResp,"data.reports[i].reporterId");
        reporterCountryCode = CkJsonObject_stringOf(jResp,"data.reports[i].reporterCountryCode");
        reporterCountryName = CkJsonObject_stringOf(jResp,"data.reports[i].reporterCountryName");
        j = 0;
        count_j = CkJsonObject_SizeOfArray(jResp,"data.reports[i].categories");
        while (j < count_j) {
            CkJsonObject_putJ(jResp,j);
            intVal = CkJsonObject_IntOf(jResp,"data.reports[i].categories[j]");
            j = j + 1;
        }

        i = i + 1;
    }



    CkHttp_Dispose(http);
    CkHttpRequest_Dispose(req);
    CkHttpResponse_Dispose(resp);
    CkJsonObject_Dispose(jResp);

    }