Skip to content

Instantly share code, notes, and snippets.

@c-lliope
Last active December 18, 2015 15:29
Show Gist options
  • Save c-lliope/5804334 to your computer and use it in GitHub Desktop.
Save c-lliope/5804334 to your computer and use it in GitHub Desktop.
Push IP address changes to DNSimple from machines with dynamic IPs
require 'dnsimple'
def update_dns
# TODO: Put DNSimple username and API Key or password in ~/.dnsimple
# See https://github.com/aetrion/dnsimple-ruby/blob/master/README.md#credentials
DNSimple::Client.load_credentials_if_necessary
# TODO replace with domain and record name
record = find_record 'example.com', 'www'
update_record_content record, local_ip
end
def find_record domain_name, record_name
domain = DNSimple::Domain.find domain_name
records = DNSimple::Record.all(domain)
records.select! do |record|
record.name == record_name
end
records.first
end
def update_record_content record, local_ip
puts "[#{Time.now}] UPDATE #{record.name}.#{record.domain.name} -> #{local_ip}"
record.content = local_ip
record.save
end
def local_ip
`curl --silent --connect-timeout 5 icanhazip.com`
end
update_dns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment