Public IPs
Here you can find different examples of actions you can do with your public_ips
Create
Creates an IP.
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: createPublicIp
# Language: Perl
#
# Description: this function creates a new public IP
###########################################################################
use strict;
use LWP::UserAgent;
use URI::Escape;
use JSON;
require Http::Request::Common;
#ID access to API
my $TOKEN = "{YOUR_API_TOKEN}"; # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
my $url = "https://cloudpanel-api.ionos.com/v1";
sub _createPublicIp
{
my ($content) = @_;
my $_command = $url ."/public_ips";
my $_method = 'POST';
#Create the request
my $ua = LWP::UserAgent->new;
my $request = HTTP::Request->new($_method => $_command);
$request->header('X-TOKEN' => $TOKEN);
$request->content_type('application/json');
#Add additional parameters
$request->content($content);
#Get the response
my $response = $ua->request($request);
if($response)
{
#Get the response and close the handlers
print $response->headers()->as_string ."\n";
return $response->content;
$response->close;
$request->close;
}
else
{
#Get the error and close the handlers
return "Http Error Code: ", $response->code, "\n";
$request->close;
}
}
#Parameters
my $reverse_dns = "example.es";
my %_query = ("reverse_dns" => $reverse_dns);
my $query = encode_json \%_query;
#Create public ip
print _createPublicIp($query);
<?php
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: createPublicIp
# Language: PHP
#
# Description: this function creates a new public IP
###########################################################################
#ID access to API
$TOKEN = "{YOUR_API_TOKEN}"; # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
$url = "https://cloudpanel-api.ionos.com/v1";
function createPublicIp($data){
global $url;
global $TOKEN;
$_command = $url . "/public_ips";
$request = curl_init();
//Set options
curl_setopt($request, CURLOPT_URL, $_command);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_HTTPHEADER, array("X-TOKEN:$TOKEN", "Content-type:application/json"));
curl_setopt($request, CURLOPT_CUSTOMREQUEST, "POST");
//Add parameters
curl_setopt($request, CURLOPT_POSTFIELDS, $data);
//Try to get the response
$response = curl_exec($request);
if ($response == false){
return( curl_error($request));
}
else{
return( $response);
}
curl_close($request);
}
#PARAMETERS
$type = "IPV4";
$data = array('type'=>$type);
$data = json_encode($data);
echo createPublicIp($data);
?>
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: createPublicIp
# Language: Python
#
# Description: this function creates a new public IP
###########################################################################
from urllib.request import Request, urlopen
import urllib
import json
#ID access to API
TOKEN = "{YOUR_API_TOKEN}" # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
url = "https://cloudpanel-api.ionos.com/v1"
def _createPublicIp(content):
#Configure the request
_command = url + "/public_ips"
_method = 'POST'
request = Request(_command, data=content.encode(encoding='utf_8'),
headers={'X-TOKEN':TOKEN, 'content-type':'application/json'},
method=_method)
#Try to get the response
try:
response = urlopen(request)
content = response.read()
return (content.decode())
#Fetch error
except urllib.error.URLError as e:
return("Error " + str(e.code) + ":" + e.reason)
#PARAMETERS
type = "IPV4"
data = json.dumps({'type':type})
#Create public Ip
print(_createPublicIp(data))
Delete
Deletes an IP.
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: deletePublicIp
# Language: Perl
#
# Description: removes public IP
###########################################################################
use strict;
use LWP::UserAgent;
use URI::Escape;
require Http::Request::Common;
#ID access to API
my $TOKEN = "{YOUR_API_TOKEN}"; # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
my $url = "https://cloudpanel-api.ionos.com/v1";
sub _deletePublicIp
{
my ($id) = @_;
my $_command = $url ."/public_ips/" .$id;
my $_method = 'DELETE';
#Create the request
my $ua = LWP::UserAgent->new;
my $request = HTTP::Request->new($_method => $_command);
$request->header('X-TOKEN' => $TOKEN);
$request->content_type('application/json');
#Get the response
my $response = $ua->request($request);
if($response)
{
#Get the response and close the handlers
print $response->headers()->as_string ."\n";
return $response->content;
$response->close;
$request->close;
}
else
{
#Get the error and close the handlers
return "Http Error Code: ", $response->code, "\n";
$request->close;
}
}
#Parameters
my $id = "{YOUR_IP_ID}"; # e.g.: "5340033E7FBBC308BC329414A0DF3C20"
#Information about public IP
print _deletePublicIp($id);
<?php
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: deletePublicIp
# Language: PHP
#
# Description: removes public IP
###########################################################################
#ID access to API
$TOKEN = "{YOUR_API_TOKEN}"; # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
$url = "https://cloudpanel-api.ionos.com/v1";
function deletePublicIp($id){
global $url;
global $TOKEN;
$_command = $url . "/public_ips/$id";
$request = curl_init();
//Set options
curl_setopt($request, CURLOPT_URL, $_command);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_HTTPHEADER, array("X-TOKEN:$TOKEN", "Content-Type:application/json"));
curl_setopt($request, CURLOPT_CUSTOMREQUEST, "DELETE");
//Try to get the response
$response = curl_exec($request);
if ($response == false){
return( curl_error($request));
}
else{
return( $response);
}
curl_close($request);
}
#PARAMETERS
$id = "{YOUR_IP_ID}"; # e.g.: "5340033E7FBBC308BC329414A0DF3C20"
echo deletePublicIp($id);
?>
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: deletePublicIp
# Language: Python
#
# Description: removes public IP
###########################################################################
from urllib.request import Request, urlopen
import urllib
import json
#ID access to API
TOKEN = "{YOUR_API_TOKEN}" # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
url = "https://cloudpanel-api.ionos.com/v1"
def _deletePublicIp(id):
#Configure the request
_command = url + "/public_ips/" + id
_method = 'DELETE'
request = Request(_command,
headers={'X-TOKEN':TOKEN, 'content-type':'application/json'},
method=_method)
#Try to get the response
try:
response = urlopen(request)
content = response.read()
return (content.decode())
#Fetch error
except urllib.error.URLError as e:
return("Error " + str(e.code) + ":" + e.reason)
#PARAMETERS
id = "{YOUR_IP_ID}" # e.g.: "5340033E7FBBC308BC329414A0DF3C20"
#Removes public IP
print(_deletePublicIp(id))
Info
Returns the information of one IP.
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: infoPublicIp
# Language: Perl
#
# Description: returns information about specific public IP
###########################################################################
use strict;
use LWP::UserAgent;
use URI::Escape;
require Http::Request::Common;
#ID access to API
my $TOKEN = "{YOUR_API_TOKEN}"; # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
my $url = "https://cloudpanel-api.ionos.com/v1";
sub _infoPublicIp
{
my ($id) = @_;
my $_command = $url ."/public_ips/" .$id;
my $_method = 'GET';
#Create the request
my $ua = LWP::UserAgent->new;
my $request = HTTP::Request->new($_method => $_command);
$request->header('X-TOKEN' => $TOKEN);
$request->content_type('application/json');
#Get the response
my $response = $ua->request($request);
if($response)
{
#Get the response and close the handlers
print $response->headers()->as_string ."\n";
return $response->content;
$response->close;
$request->close;
}
else
{
#Get the error and close the handlers
return "Http Error Code: ", $response->code, "\n";
$request->close;
}
}
#Parameters
my $id = "{YOUR_IP_ID}"; # e.g.: "5340033E7FBBC308BC329414A0DF3C20"
#Information about public IP
print _infoPublicIp($id);
<?php
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: infoPublicIp
# Language: PHP
#
# Description: returns information about specific public IP
###########################################################################
#ID access to API
$TOKEN = "{YOUR_API_TOKEN}"; # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
$url = "https://cloudpanel-api.ionos.com/v1";
function infoPublicIp($id){
global $url;
global $TOKEN;
$_command = $url . "/public_ips/$id";
$request = curl_init();
//Set options
curl_setopt($request, CURLOPT_URL, $_command);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_HTTPHEADER, array("X-TOKEN:$TOKEN", "Content-Type:application/json"));
curl_setopt($request, CURLOPT_CUSTOMREQUEST, "GET");
//Try to get the response
$response = curl_exec($request);
if ($response == false){
return( curl_error($request));
}
else{
return( $response);
}
curl_close($request);
}
#PARAMETERS
$id = "{YOUR_IP_ID}"; # e.g.: "5340033E7FBBC308BC329414A0DF3C20"
echo infoPublicIp($id);
?>
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: infoPublicIp
# Language: Python
#
# Description: returns information about specific public IP
###########################################################################
from urllib.request import Request, urlopen
import urllib
import json
#ID access to API
TOKEN = "{YOUR_API_TOKEN}" # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
url = "https://cloudpanel-api.ionos.com/v1"
def _infoPublicIp(id):
#Configure the request
_command = url + "/public_ips/" + id
_method = 'GET'
request = Request(_command,
headers={'X-TOKEN':TOKEN, 'content-type':'application/json'},
method=_method)
#Try to get the response
try:
response = urlopen(request)
content = response.read()
return (content.decode())
#Fetch error
except urllib.error.URLError as e:
return("Error " + str(e.code) + ":" + e.reason)
#PARAMETERS
id = "{YOUR_IP_ID}" # e.g.: "5340033E7FBBC308BC329414A0DF3C20"
#Information about public IP
print(_infoPublicIp(id))
List
Returns a list of all Ips.
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: listPublicIps
# Language: Perl
#
# Description: this function returns a list with public IPs
###########################################################################
use strict;
use LWP::UserAgent;
use URI::Escape;
require Http::Request::Common;
#ID access to API
my $TOKEN = "{YOUR_API_TOKEN}"; # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
my $url = "https://cloudpanel-api.ionos.com/v1";
sub _listPublicIps
{
my $_command = $url ."/public_ips";
my $_method = 'GET';
#Create the request
my $ua = LWP::UserAgent->new;
my $request = HTTP::Request->new($_method => $_command);
$request->header('X-TOKEN' => $TOKEN);
$request->content_type('application/json');
#Get the response
my $response = $ua->request($request);
if($response)
{
#Get the response and close the handlers
print $response->headers()->as_string ."\n";
return $response->content;
$response->close;
$request->close;
}
else
{
#Get the error and close the handlers
return "Http Error Code: ", $response->code, "\n";
$request->close;
}
}
#List public ips
print _listPublicIps;
<?php
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: listPublicIps
# Language: PHP
#
# Description: this function returns a list with public IPs
###########################################################################
#ID access to API
$TOKEN = "{YOUR_API_TOKEN}"; # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
$url = "https://cloudpanel-api.ionos.com/v1";
function listPublicIps(){
global $url;
global $TOKEN;
$_command = $url . "/public_ips";
$request = curl_init();
//Set options
curl_setopt($request, CURLOPT_URL, $_command);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_HTTPHEADER, array("X-TOKEN:$TOKEN", "Content-Type:application/json"));
curl_setopt($request, CURLOPT_CUSTOMREQUEST, "GET");
//Try to get the response
$response = curl_exec($request);
if ($response == false){
return( curl_error($request));
}
else{
return( $response);
}
curl_close($request);
}
#PARAMETERS
echo listPublicIps();
?>
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: listPublicIps
# Language: Python
#
# Description: this function returns a list with public IPs
###########################################################################
from urllib.request import Request, urlopen
import urllib
import json
#ID access to API
TOKEN = "{YOUR_API_TOKEN}" # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
url = "https://cloudpanel-api.ionos.com/v1"
def _listPublicIPs():
#Configure the request
_command = url + "/public_ips"
_method = 'GET'
request = Request(_command,
headers={'X-TOKEN':TOKEN, 'content-type':'application/json'},
method=_method)
#Try to get the response
try:
response = urlopen(request)
content = response.read()
return (content.decode())
#Fetch error
except urllib.error.URLError as e:
return("Error " + str(e.code) + ":" + e.reason)
#PARAMETERS
#List public IPs
print(_listPublicIPs())
Reverse DNS
Returns a reverse of the Dns of a Public Ip.
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: reverseDnsPublicIp
# Language: Perl
#
# Description: this function set reverse DNS name
###########################################################################
use strict;
use LWP::UserAgent;
use URI::Escape;
use JSON;
require Http::Request::Common;
#ID access to API
my $TOKEN = "{YOUR_API_TOKEN}"; # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
my $url = "https://cloudpanel-api.ionos.com/v1";
sub _reverseDnsPublicIp
{
my ($id, $content) = @_;
my $_command = $url ."/public_ips/" .$id;
my $_method = 'PUT';
#Create the request
my $ua = LWP::UserAgent->new;
my $request = HTTP::Request->new($_method => $_command);
$request->header('X-TOKEN' => $TOKEN);
$request->content_type('application/json');
#Add additional parameters
$request->content($content);
#Get the response
my $response = $ua->request($request);
if($response)
{
#Get the response and close the handlers
print $response->headers()->as_string ."\n";
return $response->content;
$response->close;
$request->close;
}
else
{
#Get the error and close the handlers
return "Http Error Code: ", $response->code, "\n";
$request->close;
}
}
#Parameters
my $id = "{YOUR_IP_ID}"; # e.g.: "5340033E7FBBC308BC329414A0DF3C20"
my $reverse_dns = "example.com";
my %_query = ("reverse_dns" => $reverse_dns);
my $query = encode_json \%_query;
#Change reverse name
print _reverseDnsPublicIp($id, $query);
<?php
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: reverseDnsPublicIp
# Language: PHP
#
# Description: this function set reverse DNS name
###########################################################################
#ID access to API
$TOKEN = "{YOUR_API_TOKEN}"; # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
$url = "https://cloudpanel-api.ionos.com/v1";
function reverseDNSPublicIp($id, $data){
global $url;
global $TOKEN;
$_command = $url . "/public_ips/$id";
$request = curl_init();
//Set options
curl_setopt($request, CURLOPT_URL, $_command);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_HTTPHEADER, array("X-TOKEN:$TOKEN", "Content-type:application/json"));
curl_setopt($request, CURLOPT_CUSTOMREQUEST, "PUT");
//Add parameters
curl_setopt($request, CURLOPT_POSTFIELDS, $data);
//Try to get the response
$response = curl_exec($request);
if ($response == false){
return( curl_error($request));
}
else{
return( $response);
}
curl_close($request);
}
#PARAMETERS
$id = "{YOUR_IP_ID}"; # e.g.: "5340033E7FBBC308BC329414A0DF3C20"
$type = "IPV4";
$reverse_dns = "example.es";
$data = array('type'=>$type, 'reverse_dns'=>$reverse_dns);
$data = json_encode($data);
echo reverseDNSPublicIp($id, $data);
?>
###########################################################################
# CLOUD SERVER API DOCUMENTATION
#
# Name: reverseDnsPublicIp
# Language: Python
#
# Description: this function set reverse DNS name
###########################################################################
from urllib.request import Request, urlopen
import urllib
import json
#ID access to API
TOKEN = "{YOUR_API_TOKEN}" # e.g.: "f03c3c76cc853ee690b879909c9c6f2a"
url = "https://cloudpanel-api.ionos.com/v1"
def _reverseDnsPublicIp(id, content):
#Configure the request
_command = url + "/public_ips/" + id
_method = 'PUT'
request = Request(_command, data=content.encode(encoding='utf_8'),
headers={'X-TOKEN':TOKEN, 'content-type':'application/json'},
method=_method)
#Try to get the response
try:
response = urlopen(request)
content = response.read()
return (content.decode())
#Fetch error
except urllib.error.URLError as e:
return("Error " + str(e.code) + ":" + e.reason)
#PARAMETERS
id = "{YOUR_IP_ID}" # e.g.: "5340033E7FBBC308BC329414A0DF3C20"
reverse_dns = 'example.com'
data = json.dumps({'reverse_dns':reverse_dns})
#Set reverse DNS
print(_reverseDnsPublicIp(id, data))