Created
June 21, 2016 23:00
-
-
Save scumola/140d56bc715d1f23c00b5fbca9d17ccc to your computer and use it in GitHub Desktop.
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 | |
require 'vendor/autoload.php'; | |
use Aws\Common\Aws; | |
// Create a service builder using a configuration file | |
$aws = Aws::factory(array( | |
'profile' => 'default', | |
'region' => 'us-east-1', | |
)); | |
// Get the client from the builder by namespace | |
$dnsClient = $aws->get('Route53'); | |
$oldip = ""; | |
while (1) { | |
$myip = chop(`/usr/bin/dig +short myip.opendns.com @resolver1.opendns.com`); | |
print "$myip\n"; | |
if (strcmp($myip,$oldip) !== 0) { | |
print_r($result = $dnsClient->changeResourceRecordSets(array( | |
// HostedZoneId is required | |
'HostedZoneId' => '/hostedzone/XXXXXXXXXXXXXX', | |
// ChangeBatch is required | |
'ChangeBatch' => array( | |
'Comment' => 'string', | |
// Changes is required | |
'Changes' => array( | |
array( | |
// Action is required | |
'Action' => 'UPSERT', | |
// ResourceRecordSet is required | |
'ResourceRecordSet' => array( | |
// Name is required | |
'Name' => 'badcheese.com', | |
// Type is required | |
'Type' => 'A', | |
'TTL' => 600, | |
'ResourceRecords' => array( | |
array( | |
// Value is required | |
'Value' => $myip, | |
), | |
), | |
), | |
), | |
), | |
), | |
))); | |
$oldip = $myip; | |
sleep (90); | |
} else { | |
sleep (900); | |
} | |
} | |
exit; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment