Skip to content

Instantly share code, notes, and snippets.

@ptts
Forked from Doxylamin/updateDns.php
Created December 2, 2017 17:00
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptts/11546e41f30a3d0c854297182947be2e to your computer and use it in GitHub Desktop.
Save ptts/11546e41f30a3d0c854297182947be2e 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);
}
?>
@padesmo
Copy link

padesmo commented Feb 21, 2021

Hey, what do u mean with "CloudFlare DNS Identifier" ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment