Skip to content

Instantly share code, notes, and snippets.

@dariks
Forked from Doxylamin/updateDns.php
Created May 7, 2018 12:33
Show Gist options
  • Select an option

  • Save dariks/7822b47528b2a1be89b3c12d84273ded to your computer and use it in GitHub Desktop.

Select an option

Save dariks/7822b47528b2a1be89b3c12d84273ded to your computer and use it in GitHub Desktop.
Cloudflare + FritzBox -> DynDNS
<?php
/*
FRITZ!Box DynDNS Howto:
Update-URL: http://your-domain.tld/filename.php?user=<username>&pass=<pass>&hostname=<domain>&myip=<ipaddr>
Domainname: dyndns.your-domain.tld
Username: your-cloudflare-email-address
Password: your-cloudflare-api-token
*/
// static config:
$cfZoneId = ""; //put your CloudFlare Zone ID here
$cfDnsId = ""; // put your CloudFlare DNS Identifier here
// dynamic config
$cfEmail = $_GET['user'];
$cfApikey = $_GET['pass'];
$updateDomain = $_GET['hostname'];
$ipAddr = $_GET['myip'];
$cfUrl = "https://api.cloudflare.com/client/v4/zones/".$cfZoneId."/dns_records/".$cfDnsId;
$data = array(
"type" => "A",
"name" => "{$updateDomain}",
"content" => "{$ipAddr}",
"ttl" => 120,
"proxied" => false,
);
$curl = curl_init($cfUrl);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json',"X-Auth-Email: $cfEmail","X-Auth-Key: $cfApikey"));
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
$response = curl_exec($curl);
if (!$response) {
die("Connection failure.");
}else{
var_dump($response);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment