Created
May 9, 2012 08:16
-
-
Save joelambert/2642900 to your computer and use it in GitHub Desktop.
Update DNS Made Easy DDNS Record with Local IP
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
#!/usr/bin/php | |
<?php | |
/** | |
* Update DNS Made Easy DDNS Record with Local IP | |
* http://www.joelambert.co.uk | |
* | |
* Copyright 2012, Joe Lambert. | |
* Free to use under the MIT license. | |
* http://joelambert.mit-license.org/ | |
*/ | |
// The record you wish to update | |
$dns_record = array( | |
// A label representation of the record | |
'label' => "*.mydomain.com", | |
// The DNS record's ID - found in the DNS Made easy control panel | |
'id' => 123456, | |
); | |
// Your DDNS username/password | |
$username = "username"; | |
$password = "password"; | |
// Work out the local IP Address | |
exec('ifconfig en1', $response); | |
$response = implode("\n", $response); | |
preg_match("/inet ([0-9\.]+)/", $response, $matches); | |
$new_ip = $matches[1]; | |
// Make the API Call | |
echo "Updating {$dns_record['label']} to $new_ip\n"; | |
$response = file_get_contents("http://www.dnsmadeeasy.com/servlet/updateip?username={$username}&password={$password}&id={$dns_record['id']}&ip={$new_ip}"); | |
echo trim($response) . "\n"; | |
// Clear the local DNS cache | |
exec('dscacheutil -flushcache'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment