Zig
Zig
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 Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
// 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
const req = try chilkat.HttpRequest.init();
defer req.deinit();
req.setHttpVerb("GET");
req.setPath("/api/v2/check");
req.setContentType("application/x-www-form-urlencoded");
req.addParam("maxAgeInDays", "90");
req.addParam("verbose", "");
req.addParam("ipAddress", "118.25.6.39");
req.addHeader("Key", "$YOUR_API_KEY");
req.addHeader("Accept", "application/json");
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpSReq("api.abuseipdb.com", 443, true, req, resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
const j_resp = try chilkat.JsonObject.init();
defer j_resp.deinit();
j_resp.load(try resp.getBodyStr(alloc)) catch {};
j_resp.setEmitCompact(false);
std.debug.print("Response Body:\n", .{});
std.debug.print("{s}\n", .{try j_resp.emit(alloc)});
const resp_status_code = resp.getStatusCode();
std.debug.print("Response Status Code = {d}\n", .{resp_status_code});
if (resp_status_code >= 400) {
std.debug.print("Response Header:\n", .{});
std.debug.print("{s}\n", .{try resp.getHeader(alloc)});
std.debug.print("Failed.\n", .{});
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
var reported_at: [:0]const u8 = "";
var comment: [:0]const u8 = "";
var reporter_id: i32 = 0;
var reporter_country_code: [:0]const u8 = "";
var reporter_country_name: [:0]const u8 = "";
var j: i32 = 0;
var count_j: i32 = 0;
var int_val: i32 = 0;
_ = try j_resp.stringOf(alloc, "data.ipAddress");
_ = j_resp.boolOf("data.isPublic");
_ = j_resp.intOf("data.ipVersion");
_ = j_resp.boolOf("data.isWhitelisted");
_ = j_resp.intOf("data.abuseConfidenceScore");
_ = try j_resp.stringOf(alloc, "data.countryCode");
_ = try j_resp.stringOf(alloc, "data.usageType");
_ = try j_resp.stringOf(alloc, "data.isp");
_ = try j_resp.stringOf(alloc, "data.domain");
_ = try j_resp.stringOf(alloc, "data.countryName");
_ = j_resp.intOf("data.totalReports");
_ = j_resp.intOf("data.numDistinctUsers");
_ = try j_resp.stringOf(alloc, "data.lastReportedAt");
var i: i32 = 0;
var count_i: i32 = j_resp.sizeOfArray("data.hostnames");
while (i < count_i) {
j_resp.setI(i);
i = i + 1;
}
i = 0;
count_i = j_resp.sizeOfArray("data.reports");
while (i < count_i) {
j_resp.setI(i);
reported_at = try j_resp.stringOf(alloc, "data.reports[i].reportedAt");
comment = try j_resp.stringOf(alloc, "data.reports[i].comment");
reporter_id = j_resp.intOf("data.reports[i].reporterId");
reporter_country_code = try j_resp.stringOf(alloc, "data.reports[i].reporterCountryCode");
reporter_country_name = try j_resp.stringOf(alloc, "data.reports[i].reporterCountryName");
j = 0;
count_j = j_resp.sizeOfArray("data.reports[i].categories");
while (j < count_j) {
j_resp.setJ(j);
int_val = j_resp.intOf("data.reports[i].categories[j]");
j = j + 1;
}
i = i + 1;
}
}