Swift
Swift
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 Swift Downloads
func chilkatTest() {
var success: Bool = false
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
// 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 = CkoHttpRequest()!
req.httpVerb = "GET"
req.path = "/api/v2/check"
req.contentType = "application/x-www-form-urlencoded"
req.addParam(name: "maxAgeInDays", value: "90")
req.addParam(name: "verbose", value: "")
req.addParam(name: "ipAddress", value: "118.25.6.39")
req.addHeader(name: "Key", value: "$YOUR_API_KEY")
req.addHeader(name: "Accept", value: "application/json")
let resp = CkoHttpResponse()!
success = http.httpSReq(domain: "api.abuseipdb.com", port: 443, ssl: true, request: req, response: resp)
if success == false {
print("\(http.lastErrorText!)")
return
}
let jResp = CkoJsonObject()!
jResp.load(json: resp.bodyStr)
jResp.emitCompact = false
print("Response Body:")
print("\(jResp.emit()!)")
var respStatusCode: Int = resp.statusCode.intValue
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: String?
var comment: String?
var reporterId: Int
var reporterCountryCode: String?
var reporterCountryName: String?
var j: Int
var count_j: Int
var intVal: Int
var dataIpAddress: String? = jResp.string(of: "data.ipAddress")
var dataIsPublic: Bool = jResp.bool(of: "data.isPublic")
var dataIpVersion: Int = jResp.int(of: "data.ipVersion").intValue
var dataIsWhitelisted: Bool = jResp.bool(of: "data.isWhitelisted")
var dataAbuseConfidenceScore: Int = jResp.int(of: "data.abuseConfidenceScore").intValue
var dataCountryCode: String? = jResp.string(of: "data.countryCode")
var dataUsageType: String? = jResp.string(of: "data.usageType")
var dataIsp: String? = jResp.string(of: "data.isp")
var dataDomain: String? = jResp.string(of: "data.domain")
var dataCountryName: String? = jResp.string(of: "data.countryName")
var dataTotalReports: Int = jResp.int(of: "data.totalReports").intValue
var dataNumDistinctUsers: Int = jResp.int(of: "data.numDistinctUsers").intValue
var dataLastReportedAt: String? = jResp.string(of: "data.lastReportedAt")
var i: Int = 0
var count_i: Int = jResp.size(ofArray: "data.hostnames").intValue
while i < count_i {
jResp.i = i
i = i + 1
}
i = 0
count_i = jResp.size(ofArray: "data.reports").intValue
while i < count_i {
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").intValue
reporterCountryCode = jResp.string(of: "data.reports[i].reporterCountryCode")
reporterCountryName = jResp.string(of: "data.reports[i].reporterCountryName")
j = 0
count_j = jResp.size(ofArray: "data.reports[i].categories").intValue
while j < count_j {
jResp.j = j
intVal = jResp.int(of: "data.reports[i].categories[j]").intValue
j = j + 1
}
i = i + 1
}
}