Skip to content

Instantly share code, notes, and snippets.

@maesitos
Created August 19, 2016 20:01
Show Gist options
  • Save maesitos/379a24f29956e404ab3a89466c34a896 to your computer and use it in GitHub Desktop.
Save maesitos/379a24f29956e404ab3a89466c34a896 to your computer and use it in GitHub Desktop.
Stupid and simple Dynamic DNS script based on Linode
require 'open-uri'
require 'json'
require 'net/http'
API_KEY = "YOUR API KEY HERE"
DOMAINID = "Your DomainID"
RESOURCEID = "The AAA resource ID already created in the DNS dashboard"
TARGET = "[remote_addr]" # Drop the brackets when using literal IPs. With [remote_addr] Linode will use the IP from where the request is received
# Uncomment this line if the SSL certificate is complaining. Disclosure:This is not a safe method
# OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
current_ip = Net::HTTP.get(URI("https://api.ipify.org"))
request = open("https://api.linode.com/?api_key=#{API_KEY}&api_action=domain.resource.list&DomainID=#{DOMAINID}&ResourceID=#{RESOURCEID}",
{ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE}).read
ip_in_records = JSON.parse(request)["DATA"].first["TARGET"] #Assuming the API KEY can only access one domain
unless ip_in_records == current_ip
puts "Actualizamos IP. Ip en el registo: #{ip_in_records}; Ip a la que se actualizara: #{current_ip}"
request = open("https://api.linode.com/?api_key=#{API_KEY}&api_action=domain.resource.update&DomainID=#{DOMAINID}&ResourceID=#{RESOURCEID}&Target=#{TARGET}").read
puts request
else
puts "La IP no ha cambiado"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment