-
-
Save postpostmodern/5571239 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/env ruby | |
require 'fog' | |
require 'open-uri' | |
class BrandsmithDNS | |
def initialize | |
@dns = Fog::DNS.new(:provider => 'rackspace', :rackspace_api_key => 'xxxxxxxxxxxxxxxxxx', :rackspace_username => 'yyyyyyyyyyyyyyyyyy') | |
@record = @dns.zones.get('11111111').records.get('A-222222222') | |
end | |
def dns_record_ip | |
@dns_record_ip ||= @record.value | |
end | |
def actual_ip | |
@actual_ip ||= open('http://whatismyip.akamai.com').read | |
end | |
def needs_update | |
dns_record_ip != actual_ip | |
end | |
def update_record | |
@record.value = actual_ip | |
@record.save | |
end | |
end | |
dns = BrandsmithDNS.new | |
puts "Current IP address: #{dns.actual_ip}" | |
puts " DNS Record: #{dns.dns_record_ip}" | |
if dns.needs_update | |
print "Updating..." | |
dns.update_record | |
puts "done." | |
else | |
puts "Nothing to update." | |
end |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>updatedns</string> | |
<key>Disabled</key> | |
<false/> | |
<key>UserName</key> | |
<string>nobody</string> | |
<key>StartInterval</key> | |
<integer>1800</integer> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/usr/local/bin/updatedns</string> | |
</array> | |
</dict> | |
</plist> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment