Skip to content

Instantly share code, notes, and snippets.

@ericdraken
Forked from alfo/cron.php
Created August 5, 2019 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericdraken/441715259f0098d0ac7a381b37a48b8c to your computer and use it in GitHub Desktop.
Save ericdraken/441715259f0098d0ac7a381b37a48b8c to your computer and use it in GitHub Desktop.
Cron job to update Cloudflare's DNS to point to your current IP address. Useful for people with dynamic public IPs because their stupid ISP won't let them have a static one.
<?php
// Grab the IP address
// This is the fastest method I've found so far
$ip = system('dig +short myip.opendns.com @resolver1.opendns.com');
// For cron logs
print "New IP is: " . $ip;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.cloudflare.com/api_json.html");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
$data = array(
'a' => 'DIUP',
'tkn' => 'put an api token in here please',
'email' => 'also an email in here',
'ip' => $ip,
'hosts' => 'comma seperated domains pls'
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
echo $output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment