Sample code for 30+ languages & platforms
Dart

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 Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  // This example assumes the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  final http = CkHttp();

  // 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

  final req = CkHttpRequest();
  req.httpVerb = 'GET';
  req.path = '/api/v2/check';
  req.contentType = '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');

  final resp = CkHttpResponse();
  try {
    http.httpSReq('api.abuseipdb.com', 443, true, req, resp);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final jResp = CkJsonObject();
  jResp.load(resp.bodyStr);
  jResp.emitCompact = false;

  print('Response Body:');
  print(jResp.emit());

  final respStatusCode = resp.statusCode;
  print('Response Status Code = $respStatusCode');
  if (respStatusCode >= 400) {
    print('Response Header:');
    print(resp.header);
    print('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

  var reportedAt = '';
  var comment = '';
  var reporterId = 0;
  var reporterCountryCode = '';
  var reporterCountryName = '';
  var j = 0;
  var countJ = 0;
  var intVal = 0;

  final dataIpAddress = jResp.stringOf('data.ipAddress');
  final dataIpVersion = jResp.intOf('data.ipVersion');
  final dataAbuseConfidenceScore = jResp.intOf('data.abuseConfidenceScore');
  final dataCountryCode = jResp.stringOf('data.countryCode');
  final dataUsageType = jResp.stringOf('data.usageType');
  final dataIsp = jResp.stringOf('data.isp');
  final dataDomain = jResp.stringOf('data.domain');
  final dataCountryName = jResp.stringOf('data.countryName');
  final dataTotalReports = jResp.intOf('data.totalReports');
  final dataNumDistinctUsers = jResp.intOf('data.numDistinctUsers');
  final dataLastReportedAt = jResp.stringOf('data.lastReportedAt');
  var i = 0;
  var countI = jResp.sizeOfArray('data.hostnames');
  while (i < countI) {
    jResp.i = i;
    i++;
  }

  i = 0;
  countI = jResp.sizeOfArray('data.reports');
  while (i < countI) {
    jResp.i = 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;
    countJ = jResp.sizeOfArray('data.reports[i].categories');
    while (j < countJ) {
      jResp.j = j;
      intVal = jResp.intOf('data.reports[i].categories[j]');
      j++;
    }

    i++;
  }
}