Skip to content

Instantly share code, notes, and snippets.

@gentlecat
Last active October 23, 2022 10:13
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save gentlecat/3149751 to your computer and use it in GitHub Desktop.
Save gentlecat/3149751 to your computer and use it in GitHub Desktop.
CloudFlare DNS records updater
<?php
/**
* Settings
*/
define('API_KEY', $_GET['apikey']); // CloudFlare API key
define('USERNAME', 'user@example.com'); // Email address used to login into CloudFlare
define('IP', getCurrentIP()); // Current IP address
echo 'Setting IP address to "' . IP . '"...<br />';
// Your web sites:
update('example.com');
update('example.net');
/**
* @return string Current IP address
*/
function getCurrentIP()
{
$source = "http://api.externalip.net/ip/";
return file_get_contents($source);
}
/**
* This function sends request to CloudFlare to change IP address of an A record with specific name
* @param $hostname Name of the record that needs to be updated
*/
function update($hostname)
{
echo "<br />Updating $hostname...<br />";
$update_url = 'https://www.cloudflare.com/api_json.html?a=DIUP&hosts='
. $hostname . '&u=' . USERNAME . '&tkn=' . API_KEY . '&ip=' . IP;
echo file_get_contents($update_url);
}
@mooglestiltzkin
Copy link

does this script support no-ip.info dynamic dns service o.O; ?

@gentlecat
Copy link
Author

I never worked with no-ip.info. But if they have web API then you can modify update() function to support it.

@ssebastianj
Copy link

Give a try to Gargoyle. I've sent a patch several months ago to support CloudFlare updating directly from router.

@kdallas
Copy link

kdallas commented Aug 6, 2013

Is this still working for you? I couldn't find any mention of "DIUP" as an action/option. I ended up writing my own solution using "rec_edit"

You can find it here:
https://gist.github.com/kdallas/6162568

@gentlecat
Copy link
Author

Yes, I still use this on my server. Works perfectly.

@kdallas
Copy link

kdallas commented Feb 3, 2014

Interesting well for what it's worth I've updated my cURL version and given you credit in the title. + star.

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