Skip to content

Instantly share code, notes, and snippets.

@lennartvdd
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lennartvdd/ef7d5b6f2a8134519ccd to your computer and use it in GitHub Desktop.
Save lennartvdd/ef7d5b6f2a8134519ccd to your computer and use it in GitHub Desktop.
TransIP API DynDNS
<?php
// --- Settings
$login = '';
$domainName = '';
$subDomain = '@';
$keyFile = 'transip.key';
$publicIpApi = 'https://api.ipify.org';
// --- Script
require_once('Transip/DomainService.php');
Transip_ApiSettings::$login = $login;
Transip_ApiSettings::$privateKey = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . $keyFile);
$currentPublicIp = file_get_contents($publicIpApi);
$domain = Transip_DomainService::getInfo($domainName);
$updatedDnsEntries = array();
foreach($domain->dnsEntries as $dnsEntry)
{
if($dnsEntry->name == $subDomain && $dnsEntry->type == 'A') {
$dnsEntry->content = $currentPublicIp;
}
$updatedDnsEntries[] = $dnsEntry;
}
Transip_DomainService::setDnsEntries($domainName, $updatedDnsEntries);
echo 'Succesfully set home.' . $domainName . ' to ip: '. $currentPublicIp . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment