Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C++) AbuseIPDB Check EndpointThe 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. For more information, see https://docs.abuseipdb.com/?shell#check-endpoint
#include <CkHttpW.h> #include <CkHttpRequestW.h> #include <CkHttpResponseW.h> #include <CkJsonObjectW.h> void ChilkatSample(void) { // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkHttpW http; bool success; // 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 CkHttpRequestW req; req.put_HttpVerb(L"GET"); req.put_Path(L"/api/v2/check"); req.put_ContentType(L"application/x-www-form-urlencoded"); req.AddParam(L"maxAgeInDays",L"90"); req.AddParam(L"verbose",L""); req.AddParam(L"ipAddress",L"118.25.6.39"); req.AddHeader(L"Key",L"$YOUR_API_KEY"); req.AddHeader(L"Accept",L"application/json"); CkHttpResponseW *resp = http.SynchronousRequest(L"api.abuseipdb.com",443,true,req); if (http.get_LastMethodSuccess() == false) { wprintf(L"%s\n",http.lastErrorText()); return; } CkJsonObjectW jResp; jResp.Load(resp->bodyStr()); jResp.put_EmitCompact(false); wprintf(L"Response Body:\n"); wprintf(L"%s\n",jResp.emit()); int respStatusCode = resp->get_StatusCode(); wprintf(L"Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { wprintf(L"Response Header:\n"); wprintf(L"%s\n",resp->header()); wprintf(L"Failed.\n"); delete resp; return; } delete resp; // 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. const wchar_t *reportedAt = 0; const wchar_t *comment = 0; int reporterId; const wchar_t *reporterCountryCode = 0; const wchar_t *reporterCountryName = 0; int j; int count_j; int intVal; const wchar_t *dataIpAddress = jResp.stringOf(L"data.ipAddress"); bool dataIsPublic = jResp.BoolOf(L"data.isPublic"); int dataIpVersion = jResp.IntOf(L"data.ipVersion"); bool dataIsWhitelisted = jResp.BoolOf(L"data.isWhitelisted"); int dataAbuseConfidenceScore = jResp.IntOf(L"data.abuseConfidenceScore"); const wchar_t *dataCountryCode = jResp.stringOf(L"data.countryCode"); const wchar_t *dataUsageType = jResp.stringOf(L"data.usageType"); const wchar_t *dataIsp = jResp.stringOf(L"data.isp"); const wchar_t *dataDomain = jResp.stringOf(L"data.domain"); const wchar_t *dataCountryName = jResp.stringOf(L"data.countryName"); int dataTotalReports = jResp.IntOf(L"data.totalReports"); int dataNumDistinctUsers = jResp.IntOf(L"data.numDistinctUsers"); const wchar_t *dataLastReportedAt = jResp.stringOf(L"data.lastReportedAt"); int i = 0; int count_i = jResp.SizeOfArray(L"data.hostnames"); while (i < count_i) { jResp.put_I(i); i = i + 1; } i = 0; count_i = jResp.SizeOfArray(L"data.reports"); while (i < count_i) { jResp.put_I(i); reportedAt = jResp.stringOf(L"data.reports[i].reportedAt"); comment = jResp.stringOf(L"data.reports[i].comment"); reporterId = jResp.IntOf(L"data.reports[i].reporterId"); reporterCountryCode = jResp.stringOf(L"data.reports[i].reporterCountryCode"); reporterCountryName = jResp.stringOf(L"data.reports[i].reporterCountryName"); j = 0; count_j = jResp.SizeOfArray(L"data.reports[i].categories"); while (j < count_j) { jResp.put_J(j); intVal = jResp.IntOf(L"data.reports[i].categories[j]"); j = j + 1; } i = i + 1; } } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.