-
Notifications
You must be signed in to change notification settings - Fork 0
/
linode_dyndns.rb
36 lines (29 loc) · 1.17 KB
/
linode_dyndns.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require 'net/http'
##
# Script to update a DNS record on your linode account to provide a dynamic dns service
# this can easily be setup as a cron job.
# 0 * * * * ruby /path/to/script/linode_update.rb
##
# Get the domain ID from going to linode and then 'Zone file', it is the number in the
# brackets next to your domain.
DOMAIN_ID = 1111
##
# Create a AAAA record and give it a name
# record the ?id=#### here
RESOURCE_ID = 12345
##
# You will have to goto your profile and generate a secret API key for this.
# You will be required to set your API_KEY to your key in your environment variables or
# directly replace here
API_KEY = ENV["API_KEY"]
##
# Requests from dyndns and extracts IP address. If you have your own server
# you could setup a page that returns the IP eg:
# @ip = request.remote_ip # in a controller action and display this on the view
# replace url with url to that page.
IP = Net::HTTP.get(URI.parse('http://checkip.dyndns.org:8245/')).
scan(/\d+\.\d+\.\d+\.\d+/).first
uri = URI("https://api.linode.com/?api_key=#{API_KEY}&" \
"api_action=domain.resource.update" \
"&domainid=#{DOMAIN_ID}&resourceid=#{RESOURCE_ID}&target=#{IP}")
puts Net::HTTP.get(uri)