Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

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 Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.Http,
  Chilkat.HttpRequest,
  Chilkat.HttpResponse,
  Chilkat.JsonObject;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  http: THttp;
  req: THttpRequest;
  resp: THttpResponse;
  jResp: TJsonObject;
  respStatusCode: Integer;
  reportedAt: string;
  comment: string;
  reporterId: Integer;
  reporterCountryCode: string;
  reporterCountryName: string;
  j: Integer;
  count_j: Integer;
  intVal: Integer;
  dataIpAddress: string;
  dataIsPublic: Boolean;
  dataIpVersion: Integer;
  dataIsWhitelisted: Boolean;
  dataAbuseConfidenceScore: Integer;
  dataCountryCode: string;
  dataUsageType: string;
  dataIsp: string;
  dataDomain: string;
  dataCountryName: string;
  dataTotalReports: Integer;
  dataNumDistinctUsers: Integer;
  dataLastReportedAt: string;
  i: Integer;
  count_i: Integer;

begin
  success := False;

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

  http := THttp.Create;

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

  req := THttpRequest.Create;
  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');

  resp := THttpResponse.Create;
  success := http.HttpSReq('api.abuseipdb.com',443,True,req,resp);
  if (success = False) then
    begin
      WriteLn(http.LastErrorText);
      Exit;
    end;

  jResp := TJsonObject.Create;
  jResp.Load(resp.BodyStr);
  jResp.EmitCompact := False;

  WriteLn('Response Body:');
  WriteLn(jResp.Emit());

  respStatusCode := resp.StatusCode;
  WriteLn('Response Status Code = ' + respStatusCode);
  if (respStatusCode >= 400) then
    begin
      WriteLn('Response Header:');
      WriteLn(resp.Header);
      WriteLn('Failed.');
      Exit;
    end;

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

  dataIpAddress := jResp.StringOf('data.ipAddress');
  dataIsPublic := jResp.BoolOf('data.isPublic');
  dataIpVersion := jResp.IntOf('data.ipVersion');
  dataIsWhitelisted := jResp.BoolOf('data.isWhitelisted');
  dataAbuseConfidenceScore := jResp.IntOf('data.abuseConfidenceScore');
  dataCountryCode := jResp.StringOf('data.countryCode');
  dataUsageType := jResp.StringOf('data.usageType');
  dataIsp := jResp.StringOf('data.isp');
  dataDomain := jResp.StringOf('data.domain');
  dataCountryName := jResp.StringOf('data.countryName');
  dataTotalReports := jResp.IntOf('data.totalReports');
  dataNumDistinctUsers := jResp.IntOf('data.numDistinctUsers');
  dataLastReportedAt := jResp.StringOf('data.lastReportedAt');
  i := 0;
  count_i := jResp.SizeOfArray('data.hostnames');
  while i < count_i do
    begin
      jResp.I := i;
      i := i + 1;
    end;

  i := 0;
  count_i := jResp.SizeOfArray('data.reports');
  while i < count_i do
    begin
      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;
      count_j := jResp.SizeOfArray('data.reports[i].categories');
      while j < count_j do
        begin
          jResp.J := j;
          intVal := jResp.IntOf('data.reports[i].categories[j]');
          j := j + 1;
        end;

      i := i + 1;
    end;



  http.Free;
  req.Free;
  resp.Free;
  jResp.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.