Skip to content

Instantly share code, notes, and snippets.

@jshawl
Created April 23, 2014 01:39
Show Gist options
  • Save jshawl/11200189 to your computer and use it in GitHub Desktop.
Save jshawl/11200189 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'open-uri'
require 'socket'
require 'net/http'
require 'net/https'
p Time.now.strftime("%d/%m/%Y %H:%M")
domain = '...'
current_ip = open('http://whatismyip.akamai.com').read
resolved_ip = IPSocket::getaddress( "..." )
do_record_id = ".."
do_client_id = "..."
do_api_key = "..."
$do_request_url = "/domains/" + domain + "/records/" + do_record_id + "/edit?client_id=" + do_client_id + "&api_key=" + do_api_key + "&data=" + current_ip
def update_ip( current_ip )
http = Net::HTTP.new('api.digitalocean.com', 443)
http.use_ssl = true
result = http.get( $do_request_url )
p result.read_body
end
if current_ip != resolved_ip
p "dont match" + current_ip + resolved_ip
update_ip( current_ip )
else
p "IPs match. Doing nothing..."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment