Using the API to Check Malicious IPs

Our API allows you to programmatically query the database of known malicious IPs. This guide explains how to integrate the API into your application to test client IPs.

Contents

API Overview

To check if an IP address is flagged in our database, you can send a simple POST request to the API. Below is an example using curl:

curl -X POST https://ip64.org/api/check_ip -H "Content-Type: application/json" -d '{"ip": "192.0.2.1"}'

Using the API in Python

Here’s how you can query the API using Python:

import requests

ip_address = "192.0.2.1"
url = "https://ip64.org/api/check_ip"
response = requests.post(url, json={"ip": ip_address})

if response.json().get("status") == "bad":
    print(f"{ip_address} is flagged as a malicious IP.")
else:
    print(f"{ip_address} is not flagged.")

Using the API in JavaScript

Here’s how you can query the API using JavaScript:

fetch('https://ip64.org/api/check_ip', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({ ip: '192.0.2.1' })
})
.then(response => response.json())
.then(data => {
    if (data.status === 'bad') {
        console.log('IP is flagged as malicious');
    } else {
        console.log('IP is not flagged');
    }
});

Using the API in Go

Here’s how you can query the API using Go:

package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
)

func main() {
    url := "https://ip64.org/api/check_ip"
    ipData := map[string]string{"ip": "192.0.2.1"}
    jsonData, _ := json.Marshal(ipData)

    resp, _ := http.Post(url, "application/json", bytes.NewBuffer(jsonData))
    defer resp.Body.Close()

    var result map[string]interface{}
    json.NewDecoder(resp.Body).Decode(&result)

    if result["status"] == "bad" {
        fmt.Println("IP is flagged as malicious")
    } else {
        fmt.Println("IP is not flagged")
    }
}

Using the API in PHP

Here’s how you can query the API using PHP:

$ip = "192.0.2.1";
$url = "https://ip64.org/api/check_ip";

$data = json_encode(array("ip" => $ip));

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\n",
        'method'  => 'POST',
        'content' => $data,
    ),
);

$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$response = json_decode($result, true);

if ($response['status'] == 'bad') {
    echo "$ip is flagged as a malicious IP.";
} else {
    echo "$ip is not flagged.";
}