Last active
August 29, 2015 14:25
-
-
Save lennartvdd/ef7d5b6f2a8134519ccd to your computer and use it in GitHub Desktop.
TransIP API DynDNS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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