-
-
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.
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 | |
// 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