Skip to content

Instantly share code, notes, and snippets.

@ericdraken

ericdraken/cron.php

Forked from alfo/cron.php
Created Aug 5, 2019
Embed
What would you like to do?
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