Skip to content

Instantly share code, notes, and snippets.

@zeptometer
Created April 2, 2017 02:25
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 zeptometer/8b6c60c5ed6836a94d7d5167bfff7d64 to your computer and use it in GitHub Desktop.
Save zeptometer/8b6c60c5ed6836a94d7d5167bfff7d64 to your computer and use it in GitHub Desktop.
require 'dozens'
require 'resolv'
user = 'hoge'
apikey = 'fuga'
def update_a(domain, sub)
if sub == "" then
whole = domain
else
whole = "#{sub}.#{domain}"
end
# check if ip address is updated
dns_ip = ""
begin
dns_ip = Resolv.getaddress(whole)
rescue Resolv::ResolvError
end
current_ip = `curl http://ieserver.net/ipcheck.shtml`
exit if dns_ip == current_ip
# update DNS info
api = Dozens::API.new(user, apikey)
api.authenticate
recordid = nil
records = api.records(domain)
if records != [] then
for x in records["record"] do
if x["name"] == whole && x["type"] = "A" then
recordid = x["id"]
break
end
end
end
if recordid then
api.update_record(recordid, {"content" => current_ip})
else
api.create_record({"domain" => domain,
"name" => sub,
"type" => "A",
"content" => current_ip})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment