Presearch and Vultr API

Cory Lewis
3 min readApr 10, 2021

Using both Presearch API and Vultr API to monitor you node.

Using Vultr you have to allow your web servers IP access to the API.

Using shared hosting sometimes the IP address you see in cPanel etc… is not the real server IP, best way to make sure you are using the correct IP for the API is to use this code on your web server.

<?php
//This one will show the IP that is listed in the cPanel
echo $_SERVER[‘SERVER_ADDR’];

echo “<br><br>API-IP: “;
//This is the IP that the API needs to successfully connect
echo file_get_contents(“https://api.ipify.org");
?>

If you use the code above the IP listed as API-IP is the one you need to use in your Vultr API settings.

Login to your Vultr account — Go to Account then click on API. You will see your API key and the allowed list of IP addresses, paste your IP into the box also in the box where it says “32” enter 32 in there as well.

The add API IP

While you are on this page, you can copy your Vultr API and paste it into your code.

Getting the Presearch API Key

Login to your Presearch node dashboard. https://nodes.presearch.org/dashboard

Click on the stats button at the bottom of the page, your API key will be listed at the bottom of the page.

Coding the API’s

Here is the code to grab some of the details from both API’s (please note that this code is just outputs raw data with no formatting. It does work, and it only shows grabbing some of the API details.)

Here is the code, you have to paste your Presearch and Vultr API keys into the code for it to work.

<?php
//
//PRESEARCH CODE
//
echo “<br> <strong>PRESEARCH API DETAILS</strong> <br><br>”;
$url = “https://nodes.presearch.org/api/nodes/status";
$api = “PASTE_YOUR_PRESEARCH_API_KEY_HERE”;
$opts = array(
‘http’=>array(
‘method’=>”GET”,
‘header’=>array(
“Accept: application/json”,
“Authorization: Bearer”)
)
);
$url = $url . ‘/’ . $api.”?stats=true”;
$result = file_get_contents($url, null, stream_context_create($opts));
$response = json_decode($result,true);

$success = $response[‘success’];
$sdate = $response[‘start_date’];
$edate = $response[‘end_date’];
echo “Success: “.$success.”<br>Start Date: “.$sdate.”<br>End Date: “.$edate;

foreach($response as $key => $value)
{
echo $value . “<br>”;
}
foreach ($value as $a=> $a_value)
{
echo $a . “<br>”;
foreach ($a_value as $b=> $b_value)
{
foreach ($b_value as $c=> $c_value)
{
echo $c_value . “<br>”;
}
}
}
echo “<br>”;
print ‘<pre>’;
print_r($response);
print ‘</pre>’;
//
//VULTR CODE
//
echo “<br> <strong>VULTR API DETAILS</strong> <br><br>”;
$url = “https://api.vultr.com/v2/";
$api = “PASTE_YOUR_VULTR_API_KEY_HERE”;
$opts = array(
‘http’=>array(
‘method’=>”GET”,
‘header’=>array(
“Accept: application/json”,
“Authorization: Bearer “ . $api)
)
);
$account = $url.”account”;
$result = file_get_contents($account, null, stream_context_create($opts));
$response = json_decode($result,true);
$name = $response[‘account’][‘name’];
$email = $response[‘account’][‘email’];
echo “Name: “.$name.”<br>Email: “.$email;

print ‘<pre>’;
print_r($response);
print ‘</pre>’;

$instances = $url.”instances”;
$result = file_get_contents($instances, null, stream_context_create($opts));
$response = json_decode($result,true);

echo “<br>”;
$id = $response[‘instances’][0][‘id’];
$main_ip = $response[‘instances’][0][‘main_ip’];
$status = $response[‘instances’][0][‘status’];
$power_status = $response[‘instances’][0][‘power_status’];
$server_status = $response[‘instances’][0][‘server_status’];

echo “ID: “.$id.”<br>IP: “.$main_ip.”<br>Status: “.$status.”<br>Power: “.$power_status.”<br>Server: “.$server_status;

print ‘<pre>’;
print_r($response);
print ‘</pre>’;
?>

Copy and paste this code add in your API keys save it as a .php file and run it.

Again, this is rough raw code and data, as I work through making it look better I will update this page and the code.

--

--