Skip to content

Instantly share code, notes, and snippets.

@scumola
Created June 21, 2016 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scumola/140d56bc715d1f23c00b5fbca9d17ccc to your computer and use it in GitHub Desktop.
Save scumola/140d56bc715d1f23c00b5fbca9d17ccc to your computer and use it in GitHub Desktop.
#!/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