Created
April 2, 2017 02:25
-
-
Save zeptometer/8b6c60c5ed6836a94d7d5167bfff7d64 to your computer and use it in GitHub Desktop.
This file contains 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
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