Skip to content

Instantly share code, notes, and snippets.

@mattiasnorell
Created August 22, 2014 12:55
Show Gist options
  • Save mattiasnorell/9a4603188c319bf268cd to your computer and use it in GitHub Desktop.
Save mattiasnorell/9a4603188c319bf268cd to your computer and use it in GitHub Desktop.
Update LoopiaDNS using Perl
#!/usr/bin/perl
use RPC::XML;
use RPC::XML::Client;
use Data::Dumper;
use Encode;
my $apiurl = 'https://api.loopia.se/RPCSERV';
my $apiusr = ' API USERNAME ';
my $apipwd = 'API PASSWORD ';
my $apicon = RPC::XML::Client->new($apiurl);
my $ip = `wget -q -O /dev/stdout icanhazip.com`;
my $domain = ' YOUR DOMAIN ';
my $sub = ' YOUR SUBDOMAIN ';
my $type = "A";
my $priority = undef;
my $ttl = "300";
my $record = { "type" => $type, "priority" => $priority, "ttl" => $ttl, "rdata" => $ip};
$RPC::XML::ENCOdING = 'UTF-8';
# Get redord id for domainname.
$getResponse = $apicon->simple_request('getZoneRecords', $apiusr, $apipwd,'',$domain,$sub);
$record->{'record_id'} = $getResponse->[0]{'record_id'};
# Update record for domainname.
$setResponse = $apicon->simple_request('updateZoneRecord', $apiusr, $apipwd,'',$domain,$sub,$record);
if($setResponse eq 'OK'){
print "\nUpdate successful - DNS for $sub.$domain updated to $ip\n";
}else{
print "\nUpdate failed - " . "\n" . "Error: ". Dumper($setResponse) . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment