Rust
Rust
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 Rust Downloads
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = chilkat::Http::new();
// 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
let req = chilkat::HttpRequest::new();
req.set_http_verb("GET");
req.set_path("/api/v2/check");
req.set_content_type("application/x-www-form-urlencoded");
req.add_param("maxAgeInDays", "90");
req.add_param("verbose", "");
req.add_param("ipAddress", "118.25.6.39");
req.add_header("Key", "$YOUR_API_KEY");
req.add_header("Accept", "application/json");
let resp = chilkat::HttpResponse::new();
if http.http_s_req("api.abuseipdb.com", 443, true, &req, &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
let j_resp = chilkat::JsonObject::new();
let _ = j_resp.load(&resp.body_str());
j_resp.set_emit_compact(false);
println!("Response Body:");
println!("{}", j_resp.emit().unwrap_or_default());
let resp_status_code = resp.status_code();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code >= 400 {
println!("Response Header:");
println!("{}", resp.header());
println!("Failed.");
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
let mut j: i32 = 0;
let mut count_j: i32 = 0;
let data_ip_address = j_resp.string_of("data.ipAddress").unwrap_or_default();
let data_is_public = j_resp.bool_of("data.isPublic");
let data_ip_version = j_resp.int_of("data.ipVersion");
let data_is_whitelisted = j_resp.bool_of("data.isWhitelisted");
let data_abuse_confidence_score = j_resp.int_of("data.abuseConfidenceScore");
let data_country_code = j_resp.string_of("data.countryCode").unwrap_or_default();
let data_usage_type = j_resp.string_of("data.usageType").unwrap_or_default();
let data_isp = j_resp.string_of("data.isp").unwrap_or_default();
let data_domain = j_resp.string_of("data.domain").unwrap_or_default();
let data_country_name = j_resp.string_of("data.countryName").unwrap_or_default();
let data_total_reports = j_resp.int_of("data.totalReports");
let data_num_distinct_users = j_resp.int_of("data.numDistinctUsers");
let data_last_reported_at = j_resp.string_of("data.lastReportedAt").unwrap_or_default();
let mut i = 0;
let mut count_i = j_resp.size_of_array("data.hostnames");
while i < count_i {
j_resp.set_i(i);
i = i + 1;
}
i = 0;
count_i = j_resp.size_of_array("data.reports");
while i < count_i {
j_resp.set_i(i);
let _ = j_resp.string_of("data.reports[i].reportedAt").unwrap_or_default();
let _ = j_resp.string_of("data.reports[i].comment").unwrap_or_default();
let _ = j_resp.int_of("data.reports[i].reporterId");
let _ = j_resp.string_of("data.reports[i].reporterCountryCode").unwrap_or_default();
let _ = j_resp.string_of("data.reports[i].reporterCountryName").unwrap_or_default();
j = 0;
count_j = j_resp.size_of_array("data.reports[i].categories");
while j < count_j {
j_resp.set_j(j);
let _ = j_resp.int_of("data.reports[i].categories[j]");
j = j + 1;
}
i = i + 1;
}