Code examples

Check a visitor against an expected country, and allow them only when the address is not a datacenter or Tor exit node.

Choose a language. Set your key in the IPZENTRA_KEY environment variable before you run the PHP, Python or Node.js example.

curl -H "X-Api-Key: YOUR_API_KEY" https://api.ipzentra.com/v1/5.9.0.1

curl -H "X-Api-Key: YOUR_API_KEY" \
  "https://api.ipzentra.com/v1/check?ip=49.207.48.1&country=IN,SG"
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$ch = curl_init('https://api.ipzentra.com/v1/check?ip=' . urlencode($ip) . '&country=IN');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 3,
    CURLOPT_HTTPHEADER => ['X-Api-Key: ' . getenv('IPZENTRA_KEY')],
]);
$res = json_decode((string)curl_exec($ch), true);
if (!empty($res['country_match']) && empty($res['is_hosting']) && empty($res['is_tor'])) {
    // allow the visitor
}
import os, requests

r = requests.get(
    "https://api.ipzentra.com/v1/check",
    params={"ip": "49.207.48.1", "country": "IN"},
    headers={"X-Api-Key": os.environ["IPZENTRA_KEY"]},
    timeout=3,
)
data = r.json()
if r.ok and data["country_match"] and not data["is_hosting"] and not data["is_tor"]:
    print("allow")
const res = await fetch(
  "https://api.ipzentra.com/v1/check?ip=49.207.48.1&country=IN",
  { headers: { "X-Api-Key": process.env.IPZENTRA_KEY } }
);
const data = await res.json();
if (res.ok && data.country_match && !data.is_hosting && !data.is_tor) {
  console.log("allow");
}
Need a hand? Search the Help Center or open a support ticket. We usually reply within one business day.