Java
Chilkat2 Java
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 Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.HttpRequest;
import com.chilkatsoft.chilkat2.HttpResponse;
import com.chilkatsoft.chilkat2.JsonObject;
public class ChilkatExample {
public static void main(String[] args) {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Http http = new Http();
// 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
HttpRequest req = new HttpRequest();
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");
HttpResponse resp = new HttpResponse();
try {
http.httpSReq("api.abuseipdb.com", 443, true, req, resp);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
JsonObject jResp = new JsonObject();
jResp.load(resp.getBodyStr());
jResp.setEmitCompact(false);
System.out.println("Response Body:");
System.out.println(jResp.emit());
int respStatusCode = resp.getStatusCode();
System.out.println("Response Status Code = " + respStatusCode);
if (respStatusCode >= 400) {
System.out.println("Response Header:");
System.out.println(resp.getHeader());
System.out.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
String reportedAt = "";
String comment = "";
int reporterId = 0;
String reporterCountryCode = "";
String reporterCountryName = "";
int j = 0;
int count_j = 0;
int intVal = 0;
String dataIpAddress = jResp.stringOf("data.ipAddress");
boolean dataIsPublic = jResp.boolOf("data.isPublic");
int dataIpVersion = jResp.intOf("data.ipVersion");
boolean dataIsWhitelisted = jResp.boolOf("data.isWhitelisted");
int dataAbuseConfidenceScore = jResp.intOf("data.abuseConfidenceScore");
String dataCountryCode = jResp.stringOf("data.countryCode");
String dataUsageType = jResp.stringOf("data.usageType");
String dataIsp = jResp.stringOf("data.isp");
String dataDomain = jResp.stringOf("data.domain");
String dataCountryName = jResp.stringOf("data.countryName");
int dataTotalReports = jResp.intOf("data.totalReports");
int dataNumDistinctUsers = jResp.intOf("data.numDistinctUsers");
String dataLastReportedAt = jResp.stringOf("data.lastReportedAt");
int i = 0;
int count_i = jResp.sizeOfArray("data.hostnames");
while (i < count_i) {
jResp.setI(i);
i = i + 1;
}
i = 0;
count_i = jResp.sizeOfArray("data.reports");
while (i < count_i) {
jResp.setI(i);
reportedAt = jResp.stringOf("data.reports[i].reportedAt");
comment = jResp.stringOf("data.reports[i].comment");
reporterId = jResp.intOf("data.reports[i].reporterId");
reporterCountryCode = jResp.stringOf("data.reports[i].reporterCountryCode");
reporterCountryName = jResp.stringOf("data.reports[i].reporterCountryName");
j = 0;
count_j = jResp.sizeOfArray("data.reports[i].categories");
while (j < count_j) {
jResp.setJ(j);
intVal = jResp.intOf("data.reports[i].categories[j]");
j = j + 1;
}
i = i + 1;
}
}
}