188 lines
5.7 KiB
HTML
188 lines
5.7 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>Blog</title>
|
|
@@include('../meta.html') @@include('../link_deps.html')
|
|
</head>
|
|
<body class="bg-base-200 flex flex-col items-center min-h-screen">
|
|
@@include('../nav.html')
|
|
<div class="flex-grow w-full max-w-4xl px-4 py-10">
|
|
<h1 class="text-5xl font-bold mb-6 text-base-content">
|
|
How to Integrate the API Data Center Check with Your Application
|
|
</h1>
|
|
<img class="mb-6" src="/assets/how-to-integrate.webp" />
|
|
<p class="mb-6 text-base-content">
|
|
You can integrate the API Data Center Check with your application by
|
|
making an API call to
|
|
<code>https://ipdatacentercheck.com/api/ip/:ip</code> authorized by
|
|
<code>x-api-key</code>. Below are examples in different programming
|
|
languages. The response will include the name of the data center, such
|
|
as <code>{datacenter: 'AWS'}</code>, if the IP is from a data center, or
|
|
<code>{datacenter: null}</code> if it is not.
|
|
</p>
|
|
|
|
<div class="tabs">
|
|
<a class="tab tab-lifted tab-active" id="javascript-tab"
|
|
>JavaScript (Node.js)</a
|
|
>
|
|
<a class="tab tab-lifted" id="python-tab">Python</a>
|
|
<a class="tab tab-lifted" id="ruby-tab">Ruby</a>
|
|
<a class="tab tab-lifted" id="php-tab">PHP</a>
|
|
<a class="tab tab-lifted" id="java-tab">Java</a>
|
|
</div>
|
|
|
|
<div id="javascript" class="tab-content">
|
|
<pre class="bg-gray-800 text-gray-200 p-4 rounded-lg overflow-auto">
|
|
<code>
|
|
const axios = require('axios');
|
|
|
|
const apiKey = 'your-api-key';
|
|
const ip = '8.8.8.8'; // Example IP
|
|
|
|
axios.get(`https://ipdatacentercheck.com/api/ip/${ip}`, {
|
|
headers: {
|
|
'x-api-key': apiKey
|
|
}
|
|
})
|
|
.then(response => {
|
|
console.log(response.data); // {datacenter: 'AWS'} or {datacenter: null}
|
|
})
|
|
.catch(error => {
|
|
console.error(error);
|
|
});
|
|
</code>
|
|
</pre>
|
|
</div>
|
|
|
|
<div id="python" class="tab-content hidden">
|
|
<pre class="bg-gray-800 text-gray-200 p-4 rounded-lg overflow-auto">
|
|
<code>
|
|
import requests
|
|
|
|
api_key = 'your-api-key'
|
|
ip = '8.8.8.8' // Example IP
|
|
|
|
url = f'https://ipdatacentercheck.com/api/ip/{ip}'
|
|
headers = {'x-api-key': api_key}
|
|
|
|
response = requests.get(url, headers=headers)
|
|
print(response.json()) // {'datacenter': 'AWS'} or {'datacenter': null}
|
|
</code>
|
|
</pre>
|
|
</div>
|
|
|
|
<div id="ruby" class="tab-content hidden">
|
|
<pre class="bg-gray-800 text-gray-200 p-4 rounded-lg overflow-auto">
|
|
<code>
|
|
require 'net/http'
|
|
require 'uri'
|
|
require 'json'
|
|
|
|
api_key = 'your-api-key'
|
|
ip = '8.8.8.8' # Example IP
|
|
|
|
uri = URI.parse("https://ipdatacentercheck.com/api/ip/#{ip}")
|
|
request = Net::HTTP::Get.new(uri)
|
|
request["x-api-key"] = api_key
|
|
|
|
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
|
http.request(request)
|
|
end
|
|
|
|
puts JSON.parse(response.body) # {'datacenter': 'AWS'} or {'datacenter': null}
|
|
</code>
|
|
</pre>
|
|
</div>
|
|
|
|
<div id="php" class="tab-content hidden">
|
|
<pre class="bg-gray-800 text-gray-200 p-4 rounded-lg overflow-auto">
|
|
<code>
|
|
<?php
|
|
$api_key = 'your-api-key';
|
|
$ip = '8.8.8.8'; // Example IP
|
|
$url = "https://ipdatacentercheck.com/api/ip/$ip";
|
|
|
|
$options = [
|
|
"http" => [
|
|
"header" => "x-api-key: $api_key"
|
|
]
|
|
];
|
|
|
|
$context = stream_context_create($options);
|
|
$response = file_get_contents($url, false, $context);
|
|
$data = json_decode($response, true);
|
|
|
|
print_r($data); // ['datacenter' => 'AWS'] or ['datacenter' => null]
|
|
?>
|
|
</code>
|
|
</pre>
|
|
</div>
|
|
|
|
<div id="java" class="tab-content hidden">
|
|
<pre class="bg-gray-800 text-gray-200 p-4 rounded-lg overflow-auto">
|
|
<code>
|
|
import java.io.BufferedReader;
|
|
import java.io.InputStreamReader;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.URL;
|
|
|
|
public class Main {
|
|
public static void main(String[] args) {
|
|
try {
|
|
String apiKey = "your-api-key";
|
|
String ip = "8.8.8.8"; // Example IP
|
|
URL obj = new URL(url);
|
|
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
|
|
con.setRequestMethod("GET");
|
|
con.setRequestProperty("x-api-key", apiKey);
|
|
|
|
int responseCode = con.getResponseCode();
|
|
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
|
String inputLine;
|
|
StringBuffer response = new StringBuffer();
|
|
|
|
while ((inputLine = in.readLine()) != null) {
|
|
response.append(inputLine);
|
|
}
|
|
in.close();
|
|
|
|
System.out.println(response.toString()); // {'datacenter': 'AWS'} or {'datacenter': null}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
</code>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
|
|
@@include('../price_card.html') @@include('../footer.html')
|
|
@@include('../script_deps.html')
|
|
<script>
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
function showTab(language) {
|
|
const tabs = document.querySelectorAll(".tab-content");
|
|
tabs.forEach((tab) => tab.classList.add("hidden"));
|
|
document.getElementById(language).classList.remove("hidden");
|
|
|
|
const tabLinks = document.querySelectorAll(".tab");
|
|
tabLinks.forEach((link) => {
|
|
link.classList.remove("tab-active");
|
|
});
|
|
document
|
|
.getElementById(`${language}-tab`)
|
|
.classList.add("tab-active");
|
|
}
|
|
|
|
const tabLinks = document.querySelectorAll(".tab");
|
|
tabLinks.forEach((link) => {
|
|
link.addEventListener("click", function () {
|
|
showTab(link.id.replace("-tab", ""));
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|