Sample code for 30+ languages & platforms
Lua

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

Lua
local chilkat = require("chilkat")

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

local 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

local req = chilkat.HttpRequest.new()
req.http_verb = "GET"
req.path = "/api/v2/check"
req.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")

local resp = chilkat.HttpResponse.new()
local success = http:http_sreq("api.abuseipdb.com", 443, true, req, resp)
if not success then
    print(http.last_error_text)
    return
end

local jResp = chilkat.JsonObject.new()
jResp:load(resp.body_str)
jResp.emit_compact = false

print("Response Body:")
print(jResp:emit())

local respStatusCode = resp.status_code
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
    print("Response Header:")
    print(resp.header)
    print("Failed.")
    return
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

local reportedAt = ""
local comment = ""
local reporterId = 0
local reporterCountryCode = ""
local reporterCountryName = ""
local j = 0
local count_j = 0
local intVal = 0

local dataIpAddress = jResp:string_of("data.ipAddress")
local dataIsPublic = jResp:bool_of("data.isPublic")
local dataIpVersion = jResp:int_of("data.ipVersion")
local dataIsWhitelisted = jResp:bool_of("data.isWhitelisted")
local dataAbuseConfidenceScore = jResp:int_of("data.abuseConfidenceScore")
local dataCountryCode = jResp:string_of("data.countryCode")
local dataUsageType = jResp:string_of("data.usageType")
local dataIsp = jResp:string_of("data.isp")
local dataDomain = jResp:string_of("data.domain")
local dataCountryName = jResp:string_of("data.countryName")
local dataTotalReports = jResp:int_of("data.totalReports")
local dataNumDistinctUsers = jResp:int_of("data.numDistinctUsers")
local dataLastReportedAt = jResp:string_of("data.lastReportedAt")
local i = 0
local count_i = jResp:size_of_array("data.hostnames")
while i < count_i do
    jResp.i = i
    i = i + 1
end

i = 0
count_i = jResp:size_of_array("data.reports")
while i < count_i do
    jResp.i = i
    reportedAt = jResp:string_of("data.reports[i].reportedAt")
    comment = jResp:string_of("data.reports[i].comment")
    reporterId = jResp:int_of("data.reports[i].reporterId")
    reporterCountryCode = jResp:string_of("data.reports[i].reporterCountryCode")
    reporterCountryName = jResp:string_of("data.reports[i].reporterCountryName")
    j = 0
    count_j = jResp:size_of_array("data.reports[i].categories")
    while j < count_j do
        jResp.j = j
        intVal = jResp:int_of("data.reports[i].categories[j]")
        j = j + 1
    end

    i = i + 1
end